Nayish Nayish - 7 months ago 62
PHP Question

Printing PHP float with 3 digits after the decimal point?

Is there an easy way to

echo
a float number with a specific amount of digits after the decimal point?

For example:
$sum = 3.1234566768;
I would like to echo $sum and get:
3.12
.

Answer Source

use number_format()

number_format($sum,2);