0

I used the tofixed() function to convert 2 decimal places to 10 decimal places. The conversion turn out to be wrong.

My code is:

var decimal = parseFloat((343993110.92)).toFixed(10);

The result in Google Chrome is:

decimal = 343993110.9200000167

In Internet explorer the result of the conversion is correct.

Question: How do I get the expected result of 343993110.9200000000 in Google Chrome?

jwpfox
  • 5,124
  • 11
  • 45
  • 42
Lejen
  • 3
  • 2
  • 1
    This is down to limitations in the `float` data type. What do you want to use the result for? If it's to show to the user, you could transform the value to a string and pad it. – Simon Brahan Dec 08 '17 at 11:33
  • 1
    @SimonBrahan The result used for calculation. I need to use 10 decimal places to calculate (sum the value with other numbers) the value accurately. And it is agreed between me and client to show the number in 10 decimal places. – Lejen Dec 08 '17 at 11:39
  • Possible duplicate of [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – CBroe Dec 08 '17 at 11:45

0 Answers0