-
-
Notifications
You must be signed in to change notification settings - Fork 714
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
pretty-format-json
modifies floating point numbers that have too many digits of precision
#780
Comments
yeah I suspect this isn't really fixable due to |
As @asottile said the problem is in |
Hi, I have a PR #818 to solve this issue. What do you think about it, can you check it please? @dougthor42 @asottile |
@asottile How would you feel about a custom json encoder/decoder that handles floats using
|
Python has no built-in arbitrary-precision floats. Here is an example:
So it doesn't matter what you use, you can't have a |
pretty-format-json
modifies floating point numbers that have too many digits of precision.Background
I have to work with JSON files that may be generated by non-python programs. These files, for whatever reason, have numbers that have up to 16 digits after the decimal place.
(It's absurd, really. The people taking these measurements are somehow able to measure 0.1μHz on a 10GHz scale?? Yeah, they're saving values like
5.9257052820783001 GHz
. Someone needs to teach them about significant figures... but that's beside the point. The point is I have to deal with this data 😒)Steps to Reproduce
Expected Output:
Actual Output:
The diff from expected is:
Version Info
Discussion
This might be something that has to be fixed within the python builtin
json
package. A custom JSON encoder/decoder that wraps things usingdecimal.Decimal
might work too.I've created a test case for this. See my high-precision-numbers branch or the diff.
I'll see if I have time to actually fix this, but I don't expect to☹️ .
The text was updated successfully, but these errors were encountered: