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.2 3 , how can i make it round up to #40.2 5 instead of going down to $40.2 0 ? Or maybe $40.2 6 to $40.2 5 ?
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
Try this:
decimal value = 40.23m;
decimal rounded = Math.Round(value * 20.0m, 0) / 20.0m;
Then rounded
is 40.25m
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.