using json.decode
many times if i have a value stored as -139.89
the value restored is -139.88999999999999
etc with most of the values i store like this (all have 2 precision digits like this one).
It is not a json problem per se, but rather floating point precision problem and how computer stored floating points. So it is mostly Lua or C specific and only thing is to round up the number to what you expect it to be, like 2 number precision http://lua-users.org/wiki/SimpleRound
perhaps it could be done on the c side to make it faster?
or if this adds a performance hit then it would be good to be able to add to json decode/encode the required precision as a parameter.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
actually I think in Lua all numbers are stored as double underneath, but for integer, without point, at least it can be determined that expected value is integer and is probably rounded internally.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Originally posted by: ar2rsawseen
It is not a json problem per se, but rather floating point precision problem and how computer stored floating points. So it is mostly Lua or C specific and only thing is to round up the number to what you expect it to be, like 2 number precision
http://lua-users.org/wiki/SimpleRound
More info:
http://stackoverflow.com/questions/3580486/lua-subtracting-decimal-numbers-doesnt-return-correct-precision
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Originally posted by: keszegh
perhaps it could be done on the c side to make it faster?
or if this adds a performance hit then it would be good to be able to add to json decode/encode the required precision as a parameter.
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Originally posted by: ar2rsawseen
Can't really do that I think, there could be multiple floats in json which require different precision
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Originally posted by: keszegh
thanks for the info.
and btw. at least if i store an integer, then they remain an integer, right?
View and moderate all "tickets Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Tickets"
Originally posted by: ar2rsawseen
actually I think in Lua all numbers are stored as double underneath, but for integer, without point, at least it can be determined that expected value is integer and is probably rounded internally.