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

Non-integer decimal numbers lose precision #216

Open
matthewdale opened this issue Jun 8, 2023 · 2 comments
Open

Non-integer decimal numbers lose precision #216

matthewdale opened this issue Jun 8, 2023 · 2 comments

Comments

@matthewdale
Copy link

Parsing a non-integer decimal number with more than about 16 digits will truncate the precision of the number to the what can be represented by a float64:

$ echo 0.123456789012345678901234567890 | gojq '. | tojson'
"0.12345678901234568"

In comparison, jq will preserve all of the decimal precision for non-arithmetic operations (e.g. . and tojson):

$ echo 0.123456789012345678901234567890 | jq '. | tojson'
"0.123456789012345678901234567890"

gojq currently supports arbitrary precision for integer values, including integer arithmetic operations. It would be great if it also supported arbitrary precision for non-integer decimal values for "passthrough" operations, and possibly arithmetic operations.

@itchyny
Copy link
Owner

itchyny commented Jun 24, 2023

This is related to the issue #212 and will be resolved by the json-number branch.

@wader
Copy link
Contributor

wader commented Jun 25, 2023

@itchyny for clarity, that would solve the pass thru part but not doing operations?

For reference @matthewdale did a draft PR for decimal support in the fq fork wader#1 but i'm a bit reluctant to add more difference to upstream unless it can be done in a easy rebase-able and maintainable way

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

3 participants