a=123.45324
is there a function that will return just 123
?
int
will always truncate towards zero:
>>> a = 123.456
>>> int(a)
123
>>> a = 0.9999
>>> int(a)
0
>>> int(-1.5)
-1
The difference between int
and math.floor
is that math.floor
returns the number as a float, and does not truncate towards zero.
Python 2.x:
import math
int( math.floor( a ) )
N.B. Due to complicated reasons involving the handling of floats, the int
cast is safe.
Python 3.x:
import math
math.floor( a )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With