How do I round out values that do not have cents and only have numbers?
Ex: 10, 20, 30, 40, 50. If person has 13, get 10, if he has 25, get 20.
How do I round out values that do not have cents and only have numbers?
Ex: 10, 20, 30, 40, 50. If person has 13, get 10, if he has 25, get 20.
Divide by 10 and use the intval()
function to grab the whole part, it will lose the part "broken", there multiply by 10 again to restore the magnitude.
If you need to round up, you would usually add another 5 or another number, depending on the intention. But this can vary.
If you need to round two houses, the size should be 100 instead of 10.
You can create a function to generalize this.
echo intval(13 / 10) * 10 . "\n";
echo intval(25 / 10) * 10 . "\n";
echo intval(137 / 10) * 10 . "\n";
See working on ideone and in PHP SandBox .
There is also the ready function round()
that does this. The decimal places parameter can be negative, meaning that the boxes are to the left of the comma, as you want. But she does not guarantee she'll be down.