0
Answer

Inconsistent result with Math.Round in C#

Vivek

Vivek

16y
5.2k
1

The Bankers rounding of Math.Round in C# gives a varied output for 2 parameters:

With the Number as 2.415 and rounding digit as 2, the output is 2.42. Whereas the ouput for 8.415 and 2 is 8.41. The later one contradicts with the Bankers rounding method of rounding the hundreths place to the next even digit.

In short,
Math.Round(2.415, 2) gives 2.42
Math.Round(8.415, 2) gives 8.41

This happens only for two number: 8.415 and 9.415...rest give the same result as 2.415.
Can anyone explain if this is a valid output or its a fault in the Math.Round function of C#?