Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Python's floor, ceil, fabs, and trunc Functions

This is a scratchpad post look at the different python math functions

python
import math

nums = [23, 37.1, 48.9, -7, -12.3, -26.9]

print("original  floor   ceil   fabs  trunc")

for num in nums:
    floored = math.floor(num)
    ceiled = math.ceil(num)
    fabsed = math.fabs(num)
    trunced = math.trunc(num)
    print(str(num).rjust(8, ' '), end=" ")
    print(str(floored).rjust(6, ' '), end=" ")
    print(str(ceiled).rjust(6, ' '), end=" ")
    print(str(fabsed).rjust(6, ' '), end=" ")
    print(str(trunced).rjust(6, ' '), end=" ")
    print()
results start

Footnotes And References