Round to next multiple of 10?

Posted on 2012-08-15
Medium Priority
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?
Question by:Tom Knowlton
  • 2

Assisted Solution

Andrew_Ellis earned 400 total points
ID: 38297830
if (n % 10)
    n = n + (10 - n % 10);

Author Comment

by:Tom Knowlton
ID: 38297847
What if

 if (n % 10)

is false?
LVL 35

Accepted Solution

Robert Schutt earned 1600 total points
ID: 38297921
since you want 30 to become 40, leave out the 'if'

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

Open in new window


Author Closing Comment

by:Tom Knowlton
ID: 38297976
Thanks for helping me get there...

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question