Home python Differences Floor () and Trunc () from Math

Differences Floor () and Trunc () from Math

Author

Date

Category

math.floor (x) – round down (up to a smaller number, I’m right?)

math.trunc (x) – truncate x to the whole

In use there is a difference, or repeat each other?


Answer 1, Authority 100%

functions at least will give different results on negative numbers:

from math import floor, trunc
Print (Floor (-3.2)) # Result: -4
Print (Trunc (-3.2)) # Result: -3

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions