0

I was expecting Math.Round() should round the below variable to -0.3679 but it is providing output as -0.3678

decimal a = -0.36785m;
Console.WriteLine(Math.Round(a, 4));

I need it to round up the values preceding with greater than or equal to 5.

Please suggest if I am doing anything wrong.

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • 1
    That's [the standard rule](https://en.wikipedia.org/wiki/Rounding#Round_half_to_even) that minimizes rounding errors. Rounding up means every operation will have a positive rounding error. Half-to-even means that half operations will have a positive and half a negative error, cancelling each other out. Most languages and CPUs use it for this reason – Panagiotis Kanavos Nov 01 '22 at 09:05
  • Try this, decimal a = -0.36785m; var myResult = Decimal.Parse(a.ToString("0.00##")); Console.WriteLine(myResult); – Rushi Sharma Nov 01 '22 at 09:20

0 Answers0