Код: Выделить всё
// incorrect rounding (double)
Console.WriteLine(Math.Round(71.335, 2, MidpointRounding.AwayFromZero)); // 71.33 (must to be 71.34)
Console.WriteLine(Math.Round(72.335, 2, MidpointRounding.AwayFromZero)); // 72.33 (must to be 72.34)
Console.WriteLine(Math.Round(73.335, 2, MidpointRounding.AwayFromZero)); // 73.33 (must to be 73.34)
// correct rounding (double)
Console.WriteLine(Math.Round(60.335, 2, MidpointRounding.AwayFromZero)); // 60.34
Console.WriteLine(Math.Round(83.335, 2, MidpointRounding.AwayFromZero)); // 83.34
// correct rounding (decimal) which was incorrect for double
Console.WriteLine(Math.Round(71.335M, 2, MidpointRounding.AwayFromZero)); // 71.34
Console.WriteLine(Math.Round(72.335M, 2, MidpointRounding.AwayFromZero)); // 72.34
Console.WriteLine(Math.Round(73.335M, 2, MidpointRounding.AwayFromZero)); // 73.34
Подробнее здесь: https://stackoverflow.com/questions/785 ... redictable