Round number to nearest twenty...



What I want to do is be able to round the value of a variable (always will be a number) to the nearest 20…

Like, if the variable is 56, it would round to 60. Or say the variable is 29, it would round to 20, but if it’s 30 it would round to 40. Or if it was 9 it would round to 0. Etc…

Any ideas?




If you check the function “ROUND” on it may be able ot help, however I suspect that you’ll need to manually create a function to handle that request…


Hmmm - maybe divide by 20 to get the whole number - then mod it by 20 to see if you have to bump it up to the next level.

$startValue = (int) $input/20;
$finalValue = ($input%20 >9)? ($startValue*20 + 20) : ($startValue * 20);

Reference: … hmetic.php … ypecasting
Ternary -


Go LIG Go… (I love the tertiary functions) 8)