math.floor() vs math.trunc()
math.floor() and math.trunc() are both Python Math Module APIs, and choosing between them is a common point of confusion. This page compares their syntax, parameters, return values, and typical use cases so you can pick the right one. math.floor(): Returns the largest integer less than or equal to x. Its syntax is math.floor(x), and it returns integer math.trunc(): Truncates the fractional part, returning the integer part. Its syntax is math.trunc(x), and it returns integer Example of math.floor(): math.floor(3.14) # 3
math.floor(-3.14) # -4. Example of math.trunc(): math.trunc(3.14) # 3
math.trunc(-3.14) # -3. Read the full references for math.floor() and math.trunc() to see parameters, edge cases, and example code side by side. Other Math Module APIs worth comparing: math.ceil(), math.fabs(), math.sqrt(), math.pow(), math.exp(), math.log(). Both belong to the Math Module category in the Python Reference documentation. Try both in the Python playground to see the behavioral difference live.