Round up a number to the nearest one hundred. We are using the modulus to accomplish this easy task.
So I was doing some stuff for a graph that needed some rounding up. Of course as usual my first thing is to google what I am looking for. But today, google had nothing for me. Probably because it was so frikken simple all other programmers don’t bother with putting it somewhere for lazy people like me to find.
function roundUpToHundred($n){
return (($n%100) > 0)?$n-($n%100) + 100:$n;
}
Here is what is going on with the simple function.
First we toss in the number, $n and we are running a short IF statement. We are using the MODULUS against the number ā$nā and 100, which gives us the remainder. If the remainder is 0 ($n%100) > 0, it is already to a hundred and return the $n with no changes. If the $n is greater than 0, we do $n-($n%100) + 100. This is the number ā (remainder) + 100. Gives us the next hundred above our number.
Learn the foundation of the DHTMLX Suite quickly while building a single page application with multiple components in harmony.
How often do you work with tables? I work with them quite a bit and styling t read more...
UPDATE!! A plugin is now available for this tutorial that includes more features read more...
When running a site with a boat load of javascript, you may want to run a script read more...
There seems to be a lot of misconceptions on the difference between the document read more...
Greetings All! Since everyone was digging the Star Comment Rating I decided that read more...
The website is superb
Math.round(val/100)*100