带有货币符号的数字格式

时间:2019-07-03 02:35:33

标签: php laravel

是否可以在四舍五入值之前放置货币符号?或其他选择。

echo number_format((float)$overall_total, 2, '.', ''); //748.10

预期输出应为:$ 748.10

4 个答案:

答案 0 :(得分:2)

$number = 1234.56;

// let's print the international format for the en_US locale
setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', $number) . "\n";
// USD 1,234.56

有关更多详细信息:https://www.php.net/manual/en/function.money-format.php

答案 1 :(得分:1)

来自tims's comment

echo '$'.number_format

答案 2 :(得分:1)

echo '$'.number_format((float)$overall_total, 2, '.', '');

答案 3 :(得分:0)

尝试使用money_format()

setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', $number) . "\n";

有关详细信息,请查看money-format.php