How to round down to nearest whole number 10 with PHP?

  • Thread starter Thread starter Freelance Web Programmer
  • Start date Start date
F

Freelance Web Programmer

Guest
I want to round down to the nearest 10 using PHP.

ie
44 round down to 40
48 round down to 40
125 round down to 120

Can someone help me? THANKS!
 
Divide it by 10, cast as an integer to truncate the decimal and multiply back by 10:

$var = 44;
$roundvar = ((int) ($var/10)) * 10;
//$roundvar should equal 40
 
Back
Top