A quick one this. How can I round down a decimal number for example: 0.305 to 0.30 with php? Using round($var) just rounds up.
Read the Manual pages
round(0.305, 2, PHP_ROUND_HALF_DOWN);
thanks but I get an error : Warning: Wrong parameter count for round().
What version of PHP are you using? You need to be using at least 5.3 for the third parameter to be handled.
Ah 5.2.4, developing on WAMP so I guess I need to update. Is there a way to accomplish this without upgrading?
The only way I can think of (and this is a hack) is
$value = floor(.305 * 100) / 100; // multiply by 100 so you get 30.5, then use floor() to drop the decimal place, then divide by 100 to get .30 or .3
Cheers, will try that now. And.... worked a treat. Many thanks.