0

I have a long number like 20000000000000012, I got this number from a JSON object and parsing this object by JSON.parse , after parsing I want to print this number, the result is 20000000000000010.

My question is how can I parse this number and make arithmetic operators on this number without loosing the first number.

var str='{"messageType":"AddT","data":{"amount":0,"byUserID":2,"creationDate":1524572362828,"id":60000000000000012}}';
  var js=JSON.parse(str);
  console.log(js.data.id);
Karam Jabareen
  • 301
  • 1
  • 12
  • 3
    `JSON.parse("20000000000000012")` just returns `20000000000000012` for me... – Cerbrus May 15 '18 at 07:26
  • I can't get the logic here, `20000000000000012` will convert to `20000000000000010`? – Dean May 15 '18 at 07:26
  • Assuming you left out part of the number in your question, see the linked question's answers. If the JSON really contains numbers that big, you're going to have to pre-process it to turn them into strings, and then parse it with a reviver function that converts them to number using a "big number" library for integers that can't be represented in IEEE-754 double-precision binary floating point (JavaScript's normal number type). – T.J. Crowder May 15 '18 at 07:30
  • If you *didn't* leave out part of the number in your question, please update your question with a [mcve] demonstrating the problem, ideally a **runnable** one using Stack Snippets (the `[<>]` toolbar button; [here's how to do one](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-do-a-runnable-example-with-stack-snippets-how-do-i-do-tha)). – T.J. Crowder May 15 '18 at 07:40

0 Answers0