I want to take a floating-point number and round it down to the nearest integer. However, if it's not a whole, I always want to round down the variable, regardless of how close it is to the next integer up. Is there a way to do this?
round() method, which converts float to its nearest integer by adding +0.5 to it's value and then truncating it.
round( ) function in C returns the nearest integer value of the float/double/long double argument passed to this function.
Float number always round up.
Simple
print int(x)
will work as well.
One of these should work:
import math math.trunc(1.5) > 1 math.trunc(-1.5) > -1 math.floor(1.5) > 1 math.floor(-1.5) > -2
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