Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rounding of floats #48

Open
goodevilgenius opened this issue Sep 17, 2016 · 4 comments
Open

Rounding of floats #48

goodevilgenius opened this issue Sep 17, 2016 · 4 comments

Comments

@goodevilgenius
Copy link

Floats are rounded very poorly in jshon.

E.g., echo [0.3] | jshon outputs:

[
 0.29999999999999999
]
@jmetzmeier
Copy link

jmetzmeier commented Sep 18, 2016

That's not rounding, that's 0.3 represented as a float.

$ python -c 'print format(0.3, ".20f")'
0.29999999999999998890

@goodevilgenius
Copy link
Author

It's still a bug. 0.29999999999999999 ≠ .3

@milhnl
Copy link

milhnl commented Dec 8, 2016

No it is not. It is literally how floats work. https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems

@Nindaleth
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants