Distinction in between Math.Floor () and also Math.Truncate ()

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

0
2019-05-07 00:05:14
Source Share
Answers: 2

Some instances :

Round(1.5) = 2
Round(2.5) = 2
Round(1.5, MidpointRounding.AwayFromZero) = 2
Round(2.5, MidpointRounding.AwayFromZero) = 3
Round(1.55, 1) = 1.6
Round(1.65, 1) = 1.6
Round(1.55, 1, MidpointRounding.AwayFromZero) = 1.6
Round(1.65, 1, MidpointRounding.AwayFromZero) = 1.7

Truncate(2.10) = 2
Truncate(2.00) = 2
Truncate(1.90) = 1
Truncate(1.80) = 1
0
2019-05-10 23:24:47
Source

Math.Floor rounds down, Math.Ceiling assemble, and also Math.Truncate rounds in the direction of absolutely no. Hence, Math.Truncate resembles Math.Floor for favorable numbers, and also like Math.Ceiling for adverse numbers. Below's the reference.

For efficiency, Math.Round rounds to the local integer. If the number is specifically midway in between 2 integers, after that it rounds in the direction of the also one. Reference.

See additionally : Pax Diablo's answer. Very advised!

0
2019-05-08 20:36:31
Source