CLDR::Number::Format::Currency - Localized currency formatter using the Unicode CLDR
This document describes CLDR::Number::Format::Currency v0.19, built with Unicode CLDR v29.
$curf = CLDR::Number::Format::Currency->new(
locale => 'en',
currency_code => 'USD',
$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); # '১,২৩,৪৫৬.০০₹'
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.
Localized currency formatter using the Unicode Common Locale Data Repository (CLDR).
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.
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.
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.
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
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.
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
¤ #,##0.00;¤ -#,##0.00
Examples: 1 for all locales
Examples: 2 for most currencies; 3 for BHD; 0 for JPY or for TWD when cash is true
Examples: 3 for root and almost all locales
Not used when value is 0.
Examples: 0 for root, en, and most locales; 2 for hi, bn, en-IN, and other locales of the Indian subcontinent
Examples: 1 for root, en, and most locales; 2 for es (excluding es-419), pt-PT, pl, and several others; 3 for lv and my
Examples: 0 for all currencies; 5 for CAD, CHF when cash is true
0 and 1 are treated the same.
CLDR Translation Guidelines: Currency Symbols
Nova Patch <email@example.com>
This project is brought to you by Shutterstock. Additional open source projects from Shutterstock can be found at code.shutterstock.com.
© 2013–2016 Shutterstock, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install CLDR::Number, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.