Solved

Stop rounding numbers

Posted on 2009-05-12
2
471 Views
Last Modified: 2012-05-06
I have the below and am horrible with JS - the number seem to be rounding - but want to leave it as is - more of a "mask" - but just want 3 places out past the decimal, but no rounding.

(parseFloat(value) * 1.0).toFixed(3)
0
Comment
Question by:tbaseflug
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 250 total points
ID: 24365956
How about "toString" and then cutting off the last digits?

var stringValue = String(8756.324932);
var pos = stringValue.indexOf(".");
var maskedValue = stringValue(0, pos + 4);
alert(maskedValue);

Open in new window

0
 
LVL 15

Assisted Solution

by:fsze88
fsze88 earned 250 total points
ID: 24366192
like this?
<script language="javascript">
 
var threedigit = new String( (parseFloat(123.456789)).toFixed(4) );
document.write( threedigit.substr(0,threedigit.length-1) );
 
 
</script>

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question