Skip to content

Comment on No JSON/MAPS interoperability in 17.0?

Comments

Its numbers representation is double-precision floating-point, meaning it's incredibly imprecise and limited.

Except that JSON actually just specifies the number type as an arbitrary precision decimal number.

Many implementations use floating point numbers when decoding JSON, but that is not inherent in JSON.

My biggest complaint about numbers in json is that often times floating point numbers get turned into integers when encoding/decoding using some implementations. (e.g. (float)2 gets encoded as just 2 and when decoding, it is an integer rather than a floating point.

Well, regardless of the specification, most JSON deserializers approximate numeric values as floats, at least in the default configuration. Enough so, that the Bitcoin exchange JSON-APIs I know of all put numbers in strings. So `{"balance": "12.65334221", "currency": "BTC"}` instead of `{"balance": 12.65334221, "currency": "BTC"}`. It would easily be pretty catastrophic if there are any rounding errors in your currency calculations, and if the bug arises already in your JSON deserializer it might be hard to detect even if your program internally employs BigNums (arbitrary precision) or such.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.