-1

What is the difference between Math.Floor() and Math.Truncate() in .NET?

For example, Math.Floor(4.4) = 4 Math.Truncate(4.4) = 4.

C.Alan
  • 11
  • 1

2 Answers2

2

These function behave differently for negative numbers.

Math.Truncate(-4.5) = -4

Math.Floor(-4.5) = -5

Sylvain
  • 417
  • 7
  • 16
-1

Math.Floor rounds down Math.Ceiling rounds up and Math.Truncate rounds towards zero. Thus, Math.Truncate is like Math.Floor for positive numbers, and like Math.Ceiling for negative numbers.

Ray Wang
  • 1
  • 2