Round a floating-point number down to the nearest integer? Round a floating-point number down to the nearest integer? python python

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:

  1. This returns a float
  2. This rounds towards -∞