Code 30: Difference between floor() and trunc() in Python | 365 days of code

Опубликовано: 26 Январь 2025
на канале: Code House
417
4

floor() method rounds a number DOWN to the nearest integer.
trunc() simply remove the decimals part.
import math
print(math.floor(8.9)) # Output is 8
print(math.trunc(8.9)) # Output is also 8
But
print(math.floor(-8.9)) # Output is -9
print(math.trunc(-8.9)) # Output is -8
Let's run
Thanks