Forum Moderators: coopster
I'm trying to pass a particular format to number_format() but for some reason it doesn't like what I'm trying to do:
$format = '2, \',\', \'.\'';
$number = '1234567.89';
echo number_format($number, $format) , '<br>';
++++
What appears is 1,234,567.89 rather than 1.234.567,89.
It's gotta be (I guess) the way that I'm escaping the decimal and thousands separator but I've tried it a number of different ways but still can't get it right.
Any ideas what I'm doing wrong?
Neophyte
From the Manual: (Emphasis Mine)
string number_format ( float $number , int $decimals , string $dec_point , string $thousands_sep )
PHP Number Format [us3.php.net]
The 2 below being a string, not an integer is one of the issues:
$format = '2, \',\', \'.\'';
I think it's best to just set this and not store it as a variable, because it's IMO not likely to change, so I really can't see the point in setting the extra variables... If you really need/want to for some reason you'll probably have to do this:
$decimal_places=2;
$decimal_separator=',';
$thousands='.';
$number = '1234567.89';
echo number_format($number, $decimal_places , $decimal_separator , $thousands) , '<br>';