Why does .NET decimal.ToString(string) round away from zero, apparently inconsistent with the language spec?

前端 未结 3 1621
一整个雨季
一整个雨季 2021-02-18 15:52

I see that, in C#, rounding a decimal, by default, uses MidpointRounding.ToEven. This is expected, and is what the C# spec dictates. However, given t

3条回答
  •  我在风中等你
    2021-02-18 16:19

    Most likely because this is the standard way of dealing with currency. The impetus for the creation of decimal was that floating point does a poor job of dealing with currency values, so you would expect it's rules to be more aligned with accounting standards than mathematical correctness.

提交回复
热议问题