Hi Guys,
I want to calculate a value in steps of 5.
17 -> 20
12 -> 15
24.5 -> 25
is this somehow possible using Modulo ?
lG
Daisy
Hi Guys,
I want to calculate a value in steps of 5.
17 -> 20
12 -> 15
24.5 -> 25
is this somehow possible using Modulo ?
lG
Daisy
Use ceil.
const x = 17
Math.ceil(x / 5) * 5; /* 20 */
            This should also work, using basic operators only.
x - x % 5 + 5
To floor instead of ceil, just omit the + 5.
That doesn't seem to achieve the desired result
Never mind, I read what you actually typed now!
You missed the first part of the equation.
12 - 12 % 5 + 5 = 15
            Am I missing something as it does not work for 5, 10, 15, etc.
15- 15 % 5 + 5 = 20
You're right... ![]()
One shouldn't do math before coffee! 
 Embarrassing!
I think we should stick with Marcus' solution! ![]()
It’s rare I get these things!
Maths isn’t my strong point, like at all!
My thinks whoever comes here looking to "Calculate MODULO" is not gonna be happy ![]()
Perhaps the title should be updated to "How do I round up a number?"
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.