PHP money format with spaces

吃可爱长大的小学妹 提交于 2019-12-05 01:30:54

You can use number-format. For example :

echo number_format($number, 2, ',', ' ');

But you will have to put the unit yourself.

Otherwise, this comment of the money_format documentation page gives a version of the function with some code that you can modify to change the thousand separator.

You can also do something like this :

$locale = localeconv();
$text = money_format('%i', $number);
$text = str_replace($locale['mon_thousands_sep'], ' ', $text);
lifecoder

see: http://php.net/manual/en/function.number-format.php

string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )

For your case:

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