Math.Round(double,digits) with numbers> 0 is conceptually very unclean. But I think it should never be used. double is a binary floating-point number and therefore does not have a clear concept of decimal digits.
I recommend using string.Format or just ToString("0.00") when you only need to round for decimal display, and decimal.Round if you need to round the actual number (for example, using it in further calculations).
Note. With decimal.Round you can specify MidpointRounding . AwayFromZero rounding is usually required, not ToEven .
With ToEven rounding is 0.005m rounded to 0.00 and 0.015 rounded to 0.02 . This is not what most people expect.
Comparisons:
- ToEven: 3.75 rounds to 3.8
- ToEven: 3.85 rounds to 3.8 (This is not what most people expect)
- AwayFromZero: 3.75 rounds to 3.8
- AwayFromZero: 3.85 rounds to 3.9
for more information see: https://msdn.microsoft.com/en-us/library/system.math.round.aspx
source share