Example of how to use number_format() in PHP
The followingPHP codeshows a simpleuse ofnumber_format() function, very usefulwhen you need tocorrectly formatnumbers.
<?php
$total = 3456789;
$quantity = 34;
$price = $total/$quantity;
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Number format test - PHP</title>
</head>
<body>
<div id="container">
<?php
echo $price;
echo "<br />";
echo number_format($price);
echo "<br />";
echo number_format($price, 1, ',', '.');
echo "<br />";
echo number_format($price, 2, ',', '.');
echo "<br />";
echo number_format($price, 3, ',', '.');
echo "<br />";
echo number_format($price, 4, ',', '.');
echo "<br />";
?>
</div>
</body>
</html>
Here is the resultof the example:
101670.26470588
101,670
101.670,3
101.670,26
101.670,265
101.670,2647