Psyche Psyche - 8 months ago 45
PHP Question

How to make number_format() not to round numbers up

I have this number:

$double = '21.188624';

After using
number_format($double, 2, ',', ' ')
I get:


But what I want is:


Any ideea how can I make this work?

Thank you.

Answer Source

number_format will always do that, your only solution is to feed it something different:

$number = intval(($number*100))/100;


$number = floor(($number*100))/100;