Solved

How do I truncate a floating point number

Posted on 2000-03-21
1
171 Views
Last Modified: 2012-05-04
I am currently using some script to add up numeric values in fields on the form to give a total. Example the values I use in the fields are .0031 + .0091 + .0080 and I get the total 0.020200000000. I would like the total to be truncated to 4 decimal places. How can this be done ?
0
Comment
Question by:pcorreya
1 Comment
 
LVL 8

Accepted Solution

by:
jbirk earned 50 total points
ID: 2643198
Math.round(num*10000)/10000

should do the trick for you.

-Josh
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Capture logon name 13 73
Javascript to set controls visibility 5 36
Javasctipt 2 26
alert(innerHTML); 8 18
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

810 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