lua-users home
lua-l archive

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


I am trying to convert a floating point number to an int and the beta
release seems to have added some more restrictions on the conversions.

> 1.00000000001//1
stdin:1: number has no integer representation

> return math.tointeger(1.00000001)
nil

> return string.format('%x',1.0000001)
stdin:1: bad argument #2 to 'format' (number has no integer representation)

> return 1.01 | 0
stdin:1: number has no integer representation

What is the current recommended method of converting a float to int?
Should it be to check if it is greater than zero and floor else use
ceiling and then finally use one of the above conversion methods?

If this behaviour is to stay, would it be time to have a cast operator
int() ?

-- 
Liam

Attachment: signature.asc
Description: OpenPGP digital signature