Feii Momo
Feii Momo

Reputation: 13

how to get numbers to a specific decimal place c#

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

Upvotes: 0

Views: 253

Answers (1)

Enigmativity
Enigmativity

Reputation: 117029

Try this:

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

Then rounded is 40.25m.

Upvotes: 6

Related Questions