python: get number without decimal places
You can use the math.trunc()
function:
a=10.2345
print(math.trunc(a))
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 )
a = 123.45324
int(a)
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.