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

Floating-point strings have trailing zeroes removed. #1550

Closed
Shaptic opened this issue Dec 9, 2017 · 2 comments
Closed

Floating-point strings have trailing zeroes removed. #1550

Shaptic opened this issue Dec 9, 2017 · 2 comments

Comments

@Shaptic
Copy link

Shaptic commented Dec 9, 2017

It's debatable whether or not this is a bug, but I'd expect the input string and the output number to be the same:

echo '{ "number": "123.450" }' | jq '.number | tonumber'
123.45

Obviously, it's easy enough to work around this (using sed to remove quotes instead, or awk to print with trailing zeroes), but it requires a non-jq solution.

@pkoppstein
Copy link
Contributor

pkoppstein commented Dec 10, 2017

@Shaptic - The problem you've noticed is just the tip of the iceberg (see e.g. https://github.com/stedolan/jq/wiki/FAQ#caveats and the currently open issues: #218 #369 #1120 #1357 #1545).

The idea of retaining and using the original representation when possible has been made, but as best I can tell, is unlikely to be incorporated into jq in the foreseeable future. More likely, perhaps, is better control of output formatting -- see #1363

In the meantime, please note that jq's string-handling capabilities can often be used to overcome jq's number-handling limitations, depending of course on the specific circumstances.

@PinkD
Copy link

PinkD commented Nov 27, 2023

I found this "feature" was fixed. Now I need to trim ending zeroes by my self.
https://github.com/jqlang/jq/wiki/FAQ#numbers

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

No branches or pull requests

4 participants