What is the difference between Math.Floor() and Math.Truncate() in .NET?
e.g. Math.Floor(5.4) = 5 Math.Truncate(5.4) = 5 – subramani
What is the difference between Math.Floor() and Math.Truncate() in .NET?
e.g. Math.Floor(5.4) = 5 Math.Truncate(5.4) = 5 – subramani
Floor(-2.1)
will result in -3
,
while Truncate(-2.1)
will result in -2
.
Truncate
"cuts" off after the decimal point.
Floor
on the other hand is a mathematical function that rounds downwards to the nearest integer.