Parameters money_format ()

I am looking at the money_format function in php and am confused about how to format it the way I want. I do not want USD in front of my line, I want a comma every 3 digits and 2 decimal points, so 12345.67 will be formed up to 12 345.67 US dollars

Thank.

+7
php currency
Jun 01 2018-10-06T00:
source share
2 answers

Have you looked at number_format ? This is a little easier, I think.

print number_format( 1234567, 2, ",", "." ); eg.

+21
Jun 01 2018-10-18T00-06-01
source share
— -

To answer the original question using money_format , it is just

 money_format('%.2n', 12345.67); 

money_format always starts with % . .2 indicates that you always want to use 2 decimal places. If you pass the integer, it will add .00 to the end. n indicates that you want to use the national format of the national currency.

It is important to note that you must correctly set the locale, since money_format is based on the locale set for LC_MONETARY . To set the locale, use setlocale . In this case, it seems to you that you want en_US .

 setlocale(LC_MONETARY, 'en_US.UTF-8'); 
+16
Mar 18 2018-12-18T00:
source share



All Articles