(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)
NumberFormatter::formatCurrency -- numfmt_format_currency — Format a currency value
面向对象风格
$value
, string $currency
) : string|false过程化风格
Format the currency value according to the formatter rules.
fmt
NumberFormatter object.
value
The numeric currency value.
currency
The 3-letter ISO 4217 currency code indicating the currency to use.
String representing the formatted currency value, 或者在失败时返回 false
.
示例 #1 numfmt_format_currency() example
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::CURRENCY );
echo numfmt_format_currency($fmt, 1234567.891234567890000, "EUR")."\n";
echo numfmt_format_currency($fmt, 1234567.891234567890000, "RUR")."\n";
$fmt = numfmt_create( 'ru_RU', NumberFormatter::CURRENCY );
echo numfmt_format_currency($fmt, 1234567.891234567890000, "EUR")."\n";
echo numfmt_format_currency($fmt, 1234567.891234567890000, "RUR")."\n";
?>
示例 #2 OO example
<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n";
echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."\n";
$fmt = new NumberFormatter( 'ru_RU', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(1234567.891234567890000, "EUR")."\n";
echo $fmt->formatCurrency(1234567.891234567890000, "RUR")."\n";
?>
以上例程会输出:
1.234.567,89 € 1.234.567,89 RUR 1 234 567,89€ 1 234 567,89р.