lua-users home
lua-l archive

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


> The problem, according to the IEEE floating point entries on Wikipedia, is that there are not enough digits specified.

This is on purpose so that numbers appear right for the casual user:

     > a=0.1
     > =a
     0.1
     > =string.format("%.17g",a)
     0.10000000000000001

We don't want needless noise when using print (and other automatic
conversions via tostring). If you need round-trip strings, then use
string.format.

This also happens in Python for instance (but I think we did not get
that idea from them):

     >>> a=0.1
     >>> a
     0.1
     >>> str(a)
     '0.1'
     >>> "{:.17g}".format(0.1)
     '0.10000000000000001'