[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [5.3] Converting a floating point number to integer.
- From: "Liam Devine" <liamdevine@...>
- Date: Sun, 16 Nov 2014 13:09:38 -0000
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