truncate integer python code example
Example 1: python truncate
import math
print(math.trunc(4.95*5.1))
# 25
Example 2: truncate toward zero python
>>> int(float(-1)/2)
0
>>> int(float(-3)/2)
-1
>>> int(float(1)/2)
0
>>> int(float(3)/2)
1
import math
print(math.trunc(4.95*5.1))
# 25
>>> int(float(-1)/2)
0
>>> int(float(-3)/2)
-1
>>> int(float(1)/2)
0
>>> int(float(3)/2)
1