Consider the following code:
decimal value = 12.345m;
Console.WriteLine(value.ToString("C"));
£12.35
Given that the default MidpointRounding mode in .NET is MidpointRounding.ToEven, why does this value round up (away from an even number, which would be 12.34) when formatting as currency?
For reference:
Console.WriteLine(decimal.Round(value, 2));
12.34
The special currency format specifier
Cwill round away from zero when rounding the decimal places:You have the fraction digits
.345and theCurrencyDecimalDigitsproperty is set to2(in this situation). This means that "right of the number of specified decimal places" is5, and that is greater or equal to5. The documentation states that in this case, the value12.345is rounded up, away from zero, to12.35.