lua-users home
lua-l archive

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


2013/3/31 Mason Mackaman <masondeanm@aol.com>:

> Can you set the decimal precision in Lua?

Not the internal precision, but you can set the
default printing format as follows:

function set_number_format(fmt)
debug.setmetatable(0,{
__tostring = function(x)
   return fmt:format(x) end})
end

> print(1/3)
0.33333333333333
> set_number_format"%.5f"
> print(1/3)
0.33333