keenerd / jshon

Jshon is a JSON parser designed for maximum convenience within the shell.
http://kmkeen.com/jshon/
MIT License
385 stars 57 forks source link

Floating point precission issues #19

Open Harvie opened 11 years ago

Harvie commented 11 years ago

Please fix working with floating point numbers... maybe use long instead of float? modify printf formating string? Really best thing that you can do is to internally store numbers as strings unless you really need to compute with them. (AFAIK there's no support for adding ar multiplying numbers, etc... jshon is just expected to take nuber on one side and print exact same number on the other end... so just check if it's number and if it is, then just store it as string).

Here's sample problem:

jshon -e e <<<'{"e":200.123456789}'
200.123457

I've also managed to get something like 22.37 translated into 22.370001 or 22.369999, but can't find the exact number which caused the problem right now...

THX for jshon. I've been planning to create something simillar till i find jshon...

keenerd commented 11 years ago

You are absolutely correct, but there does not seem to be a way to get this info out of the jansson library.