Reputation:
I have this number :
b = 1.324567890123456789
and the question was ask how was it stored in lua? Now when I type print(b), it shows that the end digits are
...1235
Now the question gave me the options of
...12345
or
...12346
or the option of none on the list -- and i was just wondering if anyone could help me solve this?
Upvotes: 1
Views: 372
Reputation: 72312
By default, Lua stores real numbers as double precision floating point values.
print
calls tostring
, which converts doubles to strings using "%.14g"
. [1]
Use string.format("%.17g",b)
if you want more decimals.
[1] https://www.lua.org/source/5.3/luaconf.h.html#LUA_NUMBER_FMT
Upvotes: 2