PHP How do I round down to two decimal places?

Adam Moss picture Adam Moss · Sep 5, 2012 · Viewed 55.6k times · Source

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.

Answer

GeoffreyB picture GeoffreyB · Sep 5, 2012

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