How to round a number up to the nearest 10 in PHP

1 Answer

0 votes
function roundUpToNearest10($num) {
    return ceil($num / 10) * 10;
}
  
echo roundUpToNearest10(33) . "\n";
echo roundUpToNearest10(59) . "\n";
echo roundUpToNearest10(599.99) . "\n";
echo roundUpToNearest10(3.14) . "\n";
echo roundUpToNearest10(2) . "\n";
echo roundUpToNearest10(19) . "\n";
echo roundUpToNearest10(-12) . "\n";
echo roundUpToNearest10(-101) . "\n";
echo roundUpToNearest10(-109) . "\n";
 
 
  
  
  
/*
run:
  
40
60
600
10
10
20
-10
-100
-100
  
*/

 



answered Jun 9, 2022 by avibootz

Related questions

1 answer 203 views
1 answer 214 views
1 answer 200 views
1 answer 192 views
1 answer 186 views
1 answer 177 views
1 answer 206 views
...