jshon
jshon copied to clipboard
Rounding of floats
Floats are rounded very poorly in jshon
.
E.g., echo [0.3] | jshon
outputs:
[
0.29999999999999999
]
That's not rounding, that's 0.3 represented as a float.
$ python -c 'print format(0.3, ".20f")'
0.29999999999999998890
It's still a bug. 0.29999999999999999 ≠ .3
No it is not. It is literally how floats work. https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
Even if that is literally how floats work, let me demonstrate how other JSON processing tools seem not to mind:
$ echo [0.3] | jq
[
0.3
]
$ python -c "import json; print(json.dumps([0.3]))"
[0.3]
It's not that unreasonable to expect that same result from another JSON tool.