4

How can I prevent jq from truncating long decimal values?

For example:

echo '18302628978110292481' | jq .

result: 18302628978110292000

helloflash
  • 2,457
  • 2
  • 15
  • 19
user2314105
  • 173
  • 1
  • 12
  • It clearly doesn't have the precision you need. Just treat it as a string. – Jeff Mercado Nov 30 '14 at 17:05
  • This appears to be the best answer http://stackoverflow.com/questions/23575963/how-to-prevent-jq-from-automatically-converting-double-to-int?rq=1 – user2314105 Nov 30 '14 at 21:53
  • The link best explains the problem http://stackoverflow.com/questions/23575963/how-to-prevent-jq-from-automatically-converting-double-to-int?rq=1 – user2314105 Nov 30 '14 at 22:04
  • Those links do not have any answers. I could not find any solution using the jq, so I decided to do a "find using regex and replace" in the input json file, and enclosed all numbers with quotes to make them strings. – MiroJanosik Jan 31 '23 at 21:50

1 Answers1

1

Javascript does not support such big numbers and so does jq. The integer size is 2^53. Check this

To make it work, you'll need to treat them as strings:

echo '"18302628978110292481"' | jq .
# Prints "18302628978110292481"
Community
  • 1
  • 1
hek2mgl
  • 152,036
  • 28
  • 249
  • 266