0
document.write(JSON.stringify(6448223430062899470));

I get the output of 6448223430062899000, how to solve the JSON. Stringify overflow, thank you

Vladyslav
  • 2,018
  • 4
  • 18
  • 44
rowele
  • 85
  • 10
  • 1
    why are you using JSON.stringify on a plain number. Answers can be given only if the question makes sense. – NiRUS Sep 23 '17 at 13:50
  • 1
    @Nirus, "why" doesn't matter, it is a legal operation. "The JSON.stringify() method converts a JavaScript value to a JSON string," from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify – Paul Sep 23 '17 at 13:54
  • my intention is to display this large integer on the page, and the direct output back causes the overflow, which needs to be converted to string and then rendered to the page. – rowele Sep 23 '17 at 13:56
  • @Paul Are you sure that works? – Gerardo Furtado Sep 23 '17 at 13:59
  • This question is not a duplicate - the "existing question" isn't the same and the accepted answer isn't really an answer. I nominate to reopen this question. – Paul Sep 23 '17 at 13:59
  • @Paul I tested it, and it's overflowing for ' ' + 6448223430062899470 – rowele Sep 23 '17 at 14:02
  • 1
    @Paul my question was a rhetoric question: it doesn't work, `6448223430062899470` is not `6448223430062899000`. Besides that, this question is clearly a duplicate, and the problem is exactly the same of the linked question. Of course you can vote to reopen it, this community is a democracy. – Gerardo Furtado Sep 23 '17 at 14:04
  • Yeah, my initial answer was incorrect. Coffee hasn't kicked in yet. This question is a "how", the other question is a "why". The answer is it can't be done - he needs to change the data type from number or break his number into two parts. Or find some library to do it for him. – Paul Sep 23 '17 at 14:08

0 Answers0