NAME
CLDR::Number::Format::Currency - Localized currency formatter using the Unicode CLDR
VERSION
This document describes CLDR::Number::Format::Currency v0.14, built with Unicode CLDR v28.
SYNOPSIS
# either
use CLDR::Number::Format::Currency;
$curf = CLDR::Number::Format::Currency->new(
locale => 'en',
currency_code => 'USD',
);
# or
use CLDR::Number;
$cldr = CLDR::Number->new(locale => 'en');
$curf = $cldr->currency_formatter(currency_code => 'USD');
# when locale is 'en' (English) and currency is USD (US dollars)
say $curf->format(9.99); # '$9.99'
# when locale is 'en-CA' (Canadian English) and currency is USD
say $curf->format(9.99); # 'US$9.99'
# when locale is 'fr-CA' (Canadian French) and currency is USD
say $curf->format(9.99); # '9,99 $ US'
# when locale is 'bn' (Bengali) and currency is INR (Indian rupees)
say $curf->format(123456); # '১,২৩,৪৫৬.০০₹'
DEPRECATION
Using the locale
method as a setter is deprecated. In the future the object’s locale will become immutable. Please see issue #38 for details and to submit comments or concerns.
DESCRIPTION
Localized currency formatter using the Unicode Common Locale Data Repository (CLDR).
Methods
- format
-
Accepts a number and returns a formatted currency value as a character string, using the currency from the currency_code attribute and localized for the current locale.
Attributes
The common attributes locale, default_locale, numbering_system, decimal_sign, group_sign, plus_sign, minus_sign, and cldr_version are described under common attributes in CLDR::Number. All attributes described here other than currency_code and cash have defaults that change depending on the current locale. The attributes currency_sign, minimum_fraction_digits, maximum_fraction_digits, and rounding_increment also change depending on the currency_code and cash values. All string attributes are expected to be character strings, not byte strings.
- currency_code
-
Default: none
Valid: ISO 4217 3-letter alphabetic currency codes
Examples:
EUR
(Euro),USD
(US Dollar),JPY
(Japanese Yen)The currency code is case-insensitive and is required in order to call the format method, but not required to instantiate this formatter object.
- currency_sign
-
Default: based on both locale and currency_code
Examples:
US$
for root, en-CA with USD;$
for en, de with USD;$US
for fr with USD;USD
for es-MX with USD - cash
-
Default: false (
0
)Formatting for cash can be different for some currencies. Setting cash to true (
1
) enables cash formatting when different from standard formatting. - pattern
-
Examples:
¤ #,##0.00
for root;¤#,##0.00
for en;#,##0.00 ¤
for de, fr;¤ #,##0.00;¤ -#,##0.00
for nl; and many other variations for different locales - minimum_integer_digits
-
Examples:
1
for all locales - minimum_fraction_digits
-
Examples:
2
for most currencies;3
for BHD;0
for JPY or for TWD when cash is true - maximum_fraction_digits
-
Examples:
2
for most currencies;3
for BHD;0
for JPY or for TWD when cash is true - primary_grouping_size
-
Examples:
3
for root and almost all localesNot used when value is
0
. - secondary_grouping_size
-
Examples:
0
for root, en, and most locales;2
for hi, bn, en-IN, and other locales of the Indian subcontinentNot used when value is
0
. - rounding_increment
-
Examples:
0
for all currencies;5
for CAD, CHF when cash is true0
and1
are treated the same.
SEE ALSO
AUTHOR
Nova Patch <patch@cpan.org>
This project is brought to you by Shutterstock. Additional open source projects from Shutterstock can be found at code.shutterstock.com.
COPYRIGHT AND LICENSE
© 2013–2015 Shutterstock, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.