wnumb icon indicating copy to clipboard operation
wnumb copied to clipboard

numbers with more then 16 digits cause some strange roundings

Open rtack opened this issue 7 years ago • 3 comments

var moneyWithDecimalMarks = wNumb({ thousand: ''', });

1234567890123456: 1'234'567'890'123'456 12345678901234567: 12'345'678'901'234'568 123456789012345678: 123'456'789'012'345'680 1234567890123456789: 1'234'567'890'123'456'800

The first one is still correct but adding more numbers results in strange effects.

rtack avatar Mar 17 '17 14:03 rtack

1234567890123456 is smaller than Number.MAX_SAFE_INTEGER, the other examples are larger. There's not a lot that can be done about this, I'm afraid.

leongersen avatar Mar 17 '17 15:03 leongersen

the limit is not documented afaict and the returned result is wrong. Instead of returning the wrong result shouldn't it return "false" just like when it cannot parse it?

rtack avatar Mar 17 '17 15:03 rtack

That would probably be a good idea. The limit is a limitation of the language, not the library. I'll add it to the docs.

leongersen avatar Mar 17 '17 15:03 leongersen