Nick Patch > CLDR-Number-0.06 > CLDR::Number::Format::Currency

Download:
CLDR-Number-0.06.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.06   Source   Latest Release: CLDR-Number-0.09

NAME ^

CLDR::Number::Format::Currency - Localized currency formatter using the Unicode CLDR

VERSION ^

This document describes CLDR::Number::Format::Currency v0.06, built with Unicode CLDR v24.

SYNOPSIS ^

    # either
    use CLDR::Number::Format::Currency;
    my $curf = CLDR::Number::Format::Currency->new(
        locale   => 'en',
        currency => 'USD',
    );

    # or
    use CLDR::Number;
    my $cldr = CLDR::Number->new(locale => 'en');
    my $curf = $cldr->currency_formatter(currency_code => 'USD');

    say $curf->format(9.99);  # '$9.99' (English / USD)

    $curf->locale('en-CA');
    say $curf->format(9.99);  # 'US$9.99' (Canadian English / USD)

    $curf->locale('fr-CA');
    say $curf->format(9.99);  # '9,99 $US' (Canadian French / USD)

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, 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 ko; 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 locales

Not 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 subcontinent

Not used when value is 0.

rounding_increment

Examples: 0 for all currencies; 5 for CAD, CHF when cash is true

0 and 1 are treated the same.

SEE ALSO ^

AUTHOR ^

Nick Patch <patch@cpan.org>

This project is brought to you by Perl CLDR and Shutterstock. Additional open source projects from Shutterstock can be found at code.shutterstock.com.

COPYRIGHT AND LICENSE ^

© 2013–2014 Shutterstock, Inc.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: