Search code examples
phpdecimalroundingnumber-formatting

PHP How do I round down to two decimal places?


I need to round down a decimal in PHP to two decimal places so that:

49.955

becomes...

49.95

I have tried number_format, but this just rounds the value to 49.96. I cannot use substr because the number may be smaller (such as 7.950). I've been unable to find an answer to this so far.

Any help much appreciated.


Solution

  • This can work: floor($number * 100) / 100