5
Consider the following code snippet:
decimal myValue = 3.045M;
Console.WriteLine("Result by Math.Round = " + Math.Round(myValue, 2));
Console.WriteLine("Result by string.Format = " + string.Format(CultureInfo.GetCultureInfo("pt-BR"), "{0:C}", myValue));
The results are:
// Result by Math.Round = 3.04
// Result by string.Format = R$3,05
I know the Math.Round()
uses IEEE 754, section 4, in accordance with that documentation, also called standard Banker’s rounding.
But why the string.Format()
as the specified crop returns a different result? I realized that the result is the same for different crops, as if the rounding method were different from the Math.Round()
.
This document from the IBGE agrees with the IEEE standard.
What is the reason for the difference and what method would be the most appropriate for financial systems?