0

I have code javascript:

valueToBelocl = 9876543210123456;
modLocale = "en-US";
valueToBelocl = valueToBelocl.toLocaleString(modLocale);

ressult: 9,876,543,210,123,460

Expected:9,876,543,210,123,456

Please help me make correct result! Thanks!

Vũ Minh Vương
  • 163
  • 6
  • 20

1 Answers1

2

The integer you are using is too long for your JavaScript implementation. You should not use integers larger than Number.MAX_SAFE_INTEGER, which is 9,007,199,254,740,991 on most engines today.

If you want to work with large integers, you should use specific libraries. This won't really help you with formatting it out-of-the-box though.

Pierre
  • 6,084
  • 5
  • 32
  • 52