You can use number_format() to achieve this:
echo number_format((float) $number, $precision, '.', '');
This will convert 1518845.756789 to 1518845.757 .
But if you just want to reduce the number of decimal places to 3 and not round , you can do the following:
$number = intval($number * ($p = pow(10, $precision))) / $p;
It may look intimidating at first, but the concept is really simple. You have a number, you multiply it by 10 3 (it becomes 1518845756.789 ), discards it by an integer, so everything after three decimal places is deleted (becomes 1518845756 ), and then divide the result by 10 3 (becomes 1518845.756 ).
Demo
source share