哈希空间 Ctrl + F 进行搜索
首页 php手册中文版 CSS中文手册 哈希文档 Markdown在线工具

NumberFormatter::formatCurrency

numfmt_format_currency

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)

NumberFormatter::formatCurrency -- numfmt_format_currencyFormat a currency value

说明

面向对象风格

public NumberFormatter::formatCurrency(float $amount, string $currency): string|false

过程化风格

numfmt_format_currency(NumberFormatter $formatter, float $amount, string $currency): string|false

Format the currency value according to the formatter rules.

参数

formatter

NumberFormatter object.

amount

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($fmt1234567.891234567890000"EUR")."\n";
echo 
numfmt_format_currency($fmt1234567.891234567890000"RUR")."\n";
$fmt numfmt_create'ru_RU'NumberFormatter::CURRENCY );
echo 
numfmt_format_currency($fmt1234567.891234567890000"EUR")."\n";
echo 
numfmt_format_currency($fmt1234567.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р.

注释

注意:

Formats achievable by this method of formatting cannot fully use the possibilities of underlying ICU library, such as to format currency with narrow currency symbol.

To fully utilize them use msgfmt_format_message().

参见

打开 哈希空间 微信小程序中查看更佳