问题
I am looking at the money_format function in php and confused on how to get it to format the way I want. I do not want USD in front of my string, I want a comma every 3 digits and 2 decimal points so 12345.67 will be formated to $12,345.67
Thanks.
回答1:
Have you looked at number_format? It's a little easier I think.
print number_format( 1234567, 2, ",", "." ); for example.
回答2:
To answer the original question using money_format, it's simply
money_format('%.2n', 12345.67);
money_format always starts with a %. The .2 indicates you want to always use 2 decimal places. If you pass a whole number it will add .00 to the end. The n indicates you want use the locale's national currency format.
It's important to note that you must have the locale set correctly since money_format is based on the locale you have set for LC_MONETARY. To set the locale use setlocale. In this case it appears you want en_US.
setlocale(LC_MONETARY, 'en_US.UTF-8');
来源:https://stackoverflow.com/questions/2952112/money-format-options