PHP code:
$val1 = 32;
$val2 = 0.00012207031255;
$res = $val1 - $val2;
echo "echo: ".$res."n";
echo "json: ".json_encode($res)."n";
echo "form: ".number_format($res, 14);
Output:
echo: 31.999877929687
json: 31.99987792968745
form: 31.99987792968745
How to display 14 decimal places in echo without number_format()
I tried setting precision=14
in php.ini
but nothing changed
3
Answers
If you want to add a Global solution for the whole project without changing each line of code you can set
ini_set('precision', 14)
in the bootstrap file or set the same value in php.ini.To format a single value you can use
sprintf()
function with 14 decimal characters format.Code :
Result :
You can try to use mathematical php module functions:
More detail is here
You can use sprintf()