lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


When does Lua decide to trim floats when doing a tostring? For example:

> "a"..tostring(0.30000000000000004).."b"
a0.3b
> "a"..tostring(0.3000000000000004).."b"
a0.3b
> "a"..tostring(0.300000000000004).."b"
a0.3b
> "a"..tostring(0.30000000000004).."b"
a0.30000000000004b

These are all valid floats. Added the a adn b to make the string clearer.

> 0.3 ~= 0.1+0.1+0.1
true
> 0.30000000000000004 == 0.1+0.1+0.1
true

I am interested as I am implementing Lua and want it to behave the same way.

Robert