0

**When I type 826074891934531585 in chrome console it gets rounded off to 826074891934531600 **

this data is coming from an api and can't change its type to string. Please helpenter image description here

When i tried to convert it to string it works fine. Any number greater that equal to 826074891934531550 is getting rounded off to 826074891934531600.

Any number less than or equal to 826074891934531549 is getting rounded off to 826074891934531500.

please help.

  • 1
    JavaScript numbers can't be that big. If you type `826074891934531585n` it should work, but you'll have to get your API to return a string so then you can convert it to a BigInt. – Pointy Dec 27 '22 at 19:37
  • The limit for number values is `Number.MAX_SAFE_INTEGER`, which is 9007199254740991. BigInt values are integers but can be as large as you want (within practical limits). – Pointy Dec 27 '22 at 19:38
  • @Pointy is there a way to convert it to bigint or string before it got rounded off..i'm using axios to get data in react – Thejeswar M Teja Dec 27 '22 at 19:42
  • 1
    JSON has no way to represent BigInt values, so your only choice is as a string, and then convert it with `BigInt(data.yourString)` – Pointy Dec 27 '22 at 19:46
  • 1
    @Pointy https://github.com/tc39/proposal-json-parse-with-source – Bergi Dec 27 '22 at 21:22
  • 1
    Btw, this is certainly not an `int8` number :-) – Bergi Dec 27 '22 at 21:24

0 Answers0