在线文档教程
PHP
Internationalization

NumberFormatter::formatCurrency

NumberFormatter::formatCurrency

numfmt_format_currency

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

NumberFormatter::formatCurrency -- numfmt_format_currency — Format a currency value

Description

Object oriented style

public string NumberFormatter::formatCurrency ( float $value , string $currency )

Procedural style

string numfmt_format_currency ( NumberFormatter $fmt , float $value , string $currency )

Format the currency value according to the formatter rules.

Parameters

fmt

NumberFormatter object.

value

The numeric currency value.

currency

The 3-letter ISO 4217 currency code indicating the currency to use.

Return Values

String representing the formatted currency value.

Examples

Example #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"; ?>

Example #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"; ?>

The above example will output:

1.234.567,89 € 1.234.567,89 RUR 1 234 567,89€ 1 234 567,89р.

See Also

  • numfmt_get_error_code() - Get formatter's last error code.

  • numfmt_format() - Format a number

  • numfmt_parse_currency() - Parse a currency number

← NumberFormatter::create

NumberFormatter::format →

© 1997–2017 The PHP Documentation Group

Licensed under the Creative Commons Attribution License v3.0 or later.

https://secure.php.net/manual/en/numberformatter.formatcurrency.php