PHP money_format与货币符号

时间:2011-04-13 13:20:00

标签: php

如何使用货币符号格式化数字正确的位置?是否允许最终用户通过键入来确定货币符号是什么更好?

1 个答案:

答案 0 :(得分:3)

你可以使用LC_MONETARY

$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

// Italian national format with 2 decimals`
setlocale(LC_MONETARY, 'it_IT');
echo money_format('%.2n', $number) . "\n";
// Eu 1.234,56