2 ms·
Arbitrary precision integers is a JavaScript implementation detail; JSON standard doesn't specify number precision.
by dchest 8y ago
Arbitrary precision integers is a JavaScript implementation detail; JSON standard doesn't specify number precision.
- josephg 8y agoHuh good to know: $ node > JSON.parse('1231231231231231231231231123123123123') 1.2312312312312312e+36 I've heard of JSON implementations in other languages making bigger JSON numbers than javascript supports; but I didn't realise JSON.parse would quietly parse them and throw away precision in the process. I wonder what the plan is for JSON serialization support of bigints. I assume there is no plan - Chrome stable 67 supports bigints, but JSON.serialize(2n) throws a TypeError.
- sharkdesk 8y agoIn theory, that is true. In practice, if the consuming client is javascript, it is really hard to map the numbers into an arbitrary precision number upon decoding (which would come from some library like big.js), rather than a pure double. Which means, in practice, you are stuck passing numbers as strings (and on the javascript side, pass that string into the arbitrary precision number library)