Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round to nearest five

I need to round a double to nearest five. I can't find a way to do it with the Math.Round function. How can I do this?

What I want:

70 = 70 73.5 = 75 72 = 70 75.9 = 75 69 = 70 

and so on..

Is there an easy way to do this?

like image 402
Martin Avatar asked Oct 07 '09 13:10

Martin


People also ask

What is round off to nearest 5?

Use your number line, number from 1-10 and jump from 9 back to 5 and from 9 forward to 10. They can see that you have to jump 4 times to get to 5 but only once to get to 10. 9 rounded of to the nearest 5 is then equal to 10.

Can you make Excel round to the nearest 5?

To round to the nearest 5 in Excel, you can use the MROUND function.


2 Answers

Try:

Math.Round(value / 5.0) * 5; 
like image 68
Sebastiaan M Avatar answered Sep 20 '22 17:09

Sebastiaan M


This works:

5* (int)Math.Round(p / 5.0) 
like image 33
Mike Polen Avatar answered Sep 18 '22 17:09

Mike Polen