Possible Duplicate:
In C#: Math.Round(2.5) result is 2 (instead of 3)! Are you kidding me?
The Math.Round function for .Net 3.5 SP1 appears to round 0.5 to zero, while it rounds 1.5 to 2.0. I have tested this with decimal numbers, and the following code:
decimal pos = 0.5m;
decimal neg = -0.5m;
Console.WriteLine("Pos: {0} Rnd: {1}", pos, Math.Round(pos));
Console.WriteLine("Neg: {0} Rnd: {1}", neg, Math.Round(neg));
Console.ReadKey();
This code outputs the following:
Pos: 0.5 Rnd: 0 Neg: -0.5 Rnd: 0
This seems like a glaring bug. Is there a known work around? I've tested this on a Core2 processor, and an i7, so it does not appear to be hardware. And Reflector just says that the decimal.round function ultimately calls a system call.
Let me know if anyone else see's this.