Hi i need to round up the value end with Zero (end value to be 0, like 450, 55000, 4560).
i want to round up the value with ending zero eg if i got value like 102498
means round up value like 102500
and if i got value like 47504 means round up value like 47500 this i have to do in mvc eg values 999 =>1000
994=>990
995=>990
i have to do this roundup in table view page.
Asked
Active
Viewed 356 times
-3
-
Are you trying to round in C# or Javascript/JQuery? You have both tagged. – Nathan Champion Jul 17 '20 at 12:23
-
@NathanChampion @{double totamt = item.PerHourRate * item.TotalHours;} @Math.Round(totamt) this only i tried but i donno how to round up with ending zero – susan Jul 17 '20 at 12:25
-
Something like this should work: https://stackoverflow.com/questions/274439/built-in-net-algorithm-to-round-value-to-the-nearest-10-interval though typically I believe the last digit of >=5 round up in most algorithms. – Nathan Champion Jul 17 '20 at 12:29
1 Answers
0
I'd suggest starting with:
Decimal value = 102498;
var rounded = Math.Round(value / 10, MidpointRounding.AwayFromZero) * 10;
Console.WriteLine(rounded);
The steps are:
- Divide by 10
- Round (.5 up, below .5 down -
AwayFromZero
) - Multiply by 10 (this ensures the last digit is always 0)

mjwills
- 23,389
- 6
- 40
- 63