0

I need

Math.Round(42.5447, 2, MidpointRounding.AwayFromZero)

to result in 42.55, but not in 42.54 as it does.

How to achieve this?

Soner Gönül
  • 94,086
  • 102
  • 195
  • 339
Andrii Muzychuk
  • 1,140
  • 2
  • 22
  • 28
  • There is no such thing as proper rounding. It is culture dependent. Use CultureInfo that fits your requirement for rounding. – bamanow Dec 05 '15 at 15:35
  • There certainly is proper rounding. But there are different rounding methods - and these are well-defined but not culture dependent. – Gustav Dec 05 '15 at 15:59
  • Wow. It appeared (for me), that this kind of rounding is for bank systems. And mathematical method will give me the same as round method gives me - 42.54. My miss. – Andrii Muzychuk Dec 05 '15 at 16:06
  • 2
    Are you sure you want to be using doubles at all? If you are doing manipulations on decimal quantities then you should be using decimal. – Eric Lippert Dec 05 '15 at 17:40
  • Possible duplicate of [C# Math.Round Up](http://stackoverflow.com/questions/24158334/c-sharp-math-round-up) – Brian Dec 07 '15 at 15:48

1 Answers1

0

Try Ceiling instead, with some multiply/divide trick:

Math.Ceiling((42.5447 * 100))/ 100
dotNET
  • 31,005
  • 20
  • 138
  • 226