Round to next multiple of 10?

Posted on 2012-08-15
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:knowlton
    LVL 1

    Assisted Solution

    if (n % 10)
        n = n + (10 - n % 10);
    LVL 5

    Author Comment

    What if

     if (n % 10)

    is false?
    LVL 35

    Accepted Solution

    since you want 30 to become 40, leave out the 'if'

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

    Open in new window

    LVL 5

    Author Closing Comment

    Thanks for helping me get there...

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now