lua-users home
lua-l archive

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


there is a new function in Lua: math.isfloat, it can used to detect whether a number is a float or not.


2013/7/7 Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>
> The only thing I found that appears to be missing is the ability to
> determine the actual type of the number.

One shouldn't need to do this but you can do it as follows:

function isinteger(x)
        return tonumber(tostring(x),10)~=nil
end

> It would be nice if there was a method to do so in Lua itself.  One use
> case is for serializing integer values to disk in text form properly.

tostring does this already.




--
regards,
Xavier Wang.