Solved

Stop rounding numbers

Posted on 2009-05-12
2
466 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
2 Comments
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 250 total points
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now