Ankit Jindal Ankit Jindal - 1 month ago 8
PHP Question

after calculating percentage in php i got 87.555555 i wanna fixed it at 87.55

<?php
var $a = 85;
var $b = 7;
var $c = $a/$b;
echo $c;
?>


Answer is
12.14285714285714


I want to fixed it as
12.14
. How can we set two digits after decimal in PHP?

Answer Source

You can use number_format:

number_format($c, 2)