Round a floating-point number down to the nearest integer?
One of these should work:
import mathmath.trunc(1.5)> 1math.trunc(-1.5)> -1math.floor(1.5)> 1math.floor(-1.5)> -2
x//1
The //
operator returns the floor of the division. Since dividing by 1 doesn't change your number, this is equivalent to floor but no import is needed. Notes:
- This returns a float
- This rounds towards -∞