Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round Up to the nearest multiple of 12 [duplicate]

Possible Duplicate:
Round number up to the nearest multiple of 3

I need a javascript call that will round numbers up to the nearest multiple of 12.

Some examples:

1 -> 12

7 -> 12

14 -> 24

27 -> 36

Does anyone know of a good method for doing this? All I can think of is "If between 1-11, make it 12. If between 13-23, make it 24, etc." But that doesn't seem very efficient.

like image 264
fullOfQuestions Avatar asked Jan 23 '13 16:01

fullOfQuestions


People also ask

How do you round to the nearest multiple?

You can use CEILING to round prices, times, instrument readings or any other numeric value. CEILING rounds up using the multiple supplied. You can use the MROUND function to round to the nearest multiple and the FLOOR function to round down to a multiple.

What is a multiple in rounding?

multiple is the multiple to use when rounding. The MROUND function rounds a number to the nearest multiple of the second argument. For example, in the above example, all retail prices have to be rounded to the nearest 5¢. To calculate the retail prices for all products we use this MROUND formula… =MROUND(C4,0.05)

How do you round to the nearest multiple in Excel?

The MROUND function in Excel rounds a given number up or down to the specified multiple. Number - the value you want to round. Multiple - the multiple to which you want to round the number. For example, the formula =MROUND(7, 2) rounds 7 to the nearest multiple of 2 and returns 8 as the result.


1 Answers

Use Math.ceil()

var n = 13;
var next = Math.ceil(n/12) * 12;
like image 132
epascarello Avatar answered Oct 13 '22 12:10

epascarello