money_format() options

早过忘川 提交于 2019-12-03 06:16:40

Have you looked at number_format? It's a little easier I think.

print number_format( 1234567, 2, ",", "." ); for example.

DriverDan

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');
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!