Alex Rivera | Logout

PHP How do I round down to two decimal places?

Asked 2012-09-05T09:06:22.393
60

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.

Edit
Report

2 Answers

1

You can use:

$num = 49.9555;
echo substr($num, 0, strpos($num, '.') + 3);
answered 2012-09-05T09:09:36.183
-1

Use formatted output

sprintf("%1.2f",49.955) //49.95

DEMO

answered 2012-09-05T09:09:27.327

Your Answer