Format a number with grouped thousands in PHP
Description
The following code shows how to format a number with grouped thousands.
Example
<?php/*from ww w. java 2 s .co m*/
$number = 1234.56;
// english notation (default)
$english_format_number = number_format($number);
echo $english_format_number;
// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
echo $nombre_format_francais;
$number = 1234.5678;
// english notation without thousands separator
$english_format_number = number_format($number, 2, '.', '');
echo $english_format_number;
// 1234.57
?>
The code above generates the following result.