Denis Denis - 3 days ago 3x Question

Why does the decimal 2.5M round to 2?

I must be missing some subtlety of .NET rounding. So I am looking at this example:

decimal num = 2.5M;
var result = Math.Round(num);

Why is
result = 2
? (I would have expected 3 since it should round up)


If you want classic rounding use

        decimal num = 2.5M;
        var result = Math.Round(num,0, MidpointRounding.AwayFromZero);

Please see;k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5.2);k(DevLang-csharp)&rd=true for details