ragulka
ragulka

Reputation: 4342

Is there a limit in Javascript to decimal places on big floats?

I'm facing the following issue/behavior:

console.log(1234567892012.123456);   // 1234567892012.1234
console.log(12345678920123.123456);  // 12345678920123.123
console.log(123456789201234.123456); // 123456789201234.12

What is causing this? Are decimal places limited for big numbers/floats?

Is it related to the IEEE 754 standard (as explained here: Is floating point math broken?)?

And finally - how can I come around this issue?

Upvotes: 1

Views: 1008

Answers (1)

Patricia Shanahan
Patricia Shanahan

Reputation: 26185

Yes, you are seeing the inherent limitations of 64-bit floating point. If you really need more than two decimal places on a number as big as 123,456,789,201,234, you need some sort of extended arithmetic library. This question has some suggestions and discussion.

Upvotes: 1

Related Questions