-1
  • Math.round in asp.net return 76854.05 instead of 76854.06 ?
  • how to solve this.
  • how to get 76854.06 value using math.round function???

1 Answers1

2

Double type should be used just for scientific calculation, for currencies, and types where rounding is important, use decimal instead:

var foobar = Math.Round(1493501.1m * 5 / 100 * 100 / 100, 2);

m suffix stands for decimal type.

Ondrej Svejdar
  • 21,349
  • 5
  • 54
  • 89
  • In particular midpoint rules make little sense when rouding `double` numbers to 1 or more decimals. Actually, both `Math.Round(74675.055, 2, MidpointRounding.AwayFromZero)` and `Math.Round(74675.055, 2, MidpointRounding.ToEven)` round ***down*** to a number that looks like `74675.05`. The "midpoint" is not really realizable. Use `decimal`. With `decimal`, both `Math.Round(74675.055m, 2, MidpointRounding.AwayFromZero)` and `Math.Round(74675.055m, 2, MidpointRounding.ToEven)` round ***up*** to `74675.06m` which is an exact number. – Jeppe Stig Nielsen Jul 29 '14 at 08:53