We help IT Professionals succeed at work.

Round to next multiple of 10?

Tom Knowlton
Tom Knowlton asked
on
Medium Priority
515 Views
Last Modified: 2012-08-15
Please provide code in C#.

How do I take a number and get the next highest multiple of 10 (NHMT)?

30 ... next NHMT would be 40

42 ... next NHMT would be 50

57 ... next NHMT would be 60

39 ... next NHMT would be 40

61 ... next NHMT would be 70

Is there a function inside of Math that does this?
Comment
Watch Question

if (n % 10)
    n = n + (10 - n % 10);
Tom KnowltonWeb developer

Author

Commented:
What if

 if (n % 10)


is false?
Software Engineer
CERTIFIED EXPERT
Commented:
since you want 30 to become 40, leave out the 'if'

another way is:
nhmt = (int)(n / 10 + 1) * 10

Open in new window

Tom KnowltonWeb developer

Author

Commented:
Thanks for helping me get there...

Explore More ContentExplore courses, solutions, and other research materials related to this topic.