How can I add commas to numbers in PHP
Solution 1:
from the php manual http://php.net/manual/en/function.number-format.php
I'm assuming you want the english format.
<?php
$number = 1234.56;
// english notation (default)
$english_format_number = number_format($number);
// 1,235
// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56
$number = 1234.5678;
// english notation with a decimal point and without thousands seperator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57
?>
my 2 cents
Solution 2:
The Following code is working for me, may be this is helpful to you.
$number = 1234.56;
echo number_format($number, 2, '.', ',');
//1,234.56
Solution 3:
$number = 1234.56;
//Vietnam notation(comma for decimal point, dot for thousand separator)
$number_format_vietnam = number_format($number, 2, ',', '.');
//1.234,56