php number_format() where formating string is a variable
I get the following error when I try to use number format in php:
Notice: A non well formed numeric value encountered
$numbe开发者_开发技巧r = 10345.34543;
$format = "0, ',', '.'";
echo number_format($number, $format);
I am almost positive it is because I'm holding the formating part in a string, but is there any way around this?
Thanks.
The format you are trying to pass the arguments in is not possible. You are passing a string instead of an int
.
The expected parameters are:
string number_format ( float $number ,
int $decimals = 0 ,
string $dec_point = '.' ,
string $thousands_sep = ',' )
you will need to pass the arguments accordingly:
echo number_format($number, 0, ",", ".");
If you have a special reason to do this the way you show, you would have to use eval()
which is highly discouraged, or maybe call_user_func_array()
but you would have to explain in detail first what you are trying to do.
精彩评论