javascript-number-formatter icon indicating copy to clipboard operation
javascript-number-formatter copied to clipboard

Incorrect result for large numbers

Open davidclark87 opened this issue 8 years ago • 5 comments

See example fiddle

  • Mask: # (for simplicity's sake)
  • Value: 12345678901234567890
  • Actual result: 12345678901234567000
  • Expected result: 12345678901234567890 (same as Value)

davidclark87 avatar Jul 28 '17 20:07 davidclark87

HI @davidclark87!

Hmm, well the number being used is larger than the Number.MAX_SAFE_INTEGER value (9007199254740991).

The internal code would need to be modified to not convert the string into a numeric value, there are several toFixed() being used and thus results in a max safe integer value restriction.

Mottie avatar Jul 28 '17 20:07 Mottie

Ah, good point @Mottie! And with that I realise this is likely not a problem for my use case. Feel free to close the issue unless you'd like to see it fixed. Thanks for all your efforts with this library!

davidclark87 avatar Jul 28 '17 21:07 davidclark87

Would be great if this supported BigJs numbers, or as you say a generic string input.

Would you be open to PRs for that? (Not volunteering just yet, but maybe in the future).

jfstephe avatar Apr 26 '18 13:04 jfstephe

Hi @jfstephe!

I was working on rewriting this library, but got distracted by life. I'd be open for a PR... I got stalled on carrying the one to the left within a string. I might have some time this weekend to work on it again, then we'll see.

Mottie avatar Apr 26 '18 20:04 Mottie

👍 for this feature

hyyan avatar Apr 26 '18 20:04 hyyan