Denis - 4 months ago 20

Vb.net Question

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`

Answer

If you want classic rounding use

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

Please see https://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k(System.Math.Round);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5.2);k(DevLang-csharp)&rd=true for details