0

im a newbie doing windows forms c# so i recently wanted to create something like a cashier payment calculation button, but then i got stucked at the rounding part. For example, if the total amount is $40.23, how can i make it round up to #40.25 instead of going down to $40.20? Or maybe $40.26 to $40.25?

the total amount values are get from textboxes and the final after-rounded value will be display in textbox as well. hope i was not being too unclear about my question. thanks guys

Feii Momo
  • 13
  • 3
  • problem is you want to round to same numbers of digits. one better solution is get the last digit of number and identify if its lesser or greater . according to that you replace that last digit. - you will get what you want. – Ajay Kumar Jan 10 '18 at 13:18

1 Answers1

6

Try this:

decimal value = 40.23m;
decimal rounded = Math.Round(value * 20.0m, 0) / 20.0m;

Then rounded is 40.25m.

Enigmativity
  • 97,521
  • 11
  • 78
  • 153