Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
113
rated 0 times [  116] [ 3]  / answers: 1 / hits: 15482  / 14 Years ago, fri, january 14, 2011, 12:00:00

Based on http://www.mredkj.com/javascript/nfbasic2.html, following code will result in 5.6e+2.



num = 555.55;
result = num.toPrecision(2); // result will equal 5.6e+2


How can I let the output of the result variable be displayed without scientific notation (i.e., e)?


More From » javascript

 Answers
2

To get a float with reduced precision, you could use toPrecision() like you do, and then parse the scientific notation with parseFloat(), like so:



result = parseFloat(num.toPrecision(2));


If you do not wish to reduce precision, you could use toFixed() to get the number with a certain number of decimals.


[#94226] Wednesday, January 12, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ellisw

Total Points: 625
Total Questions: 92
Total Answers: 88

Location: Kazakhstan
Member since Mon, Sep 26, 2022
2 Years ago
;