<<

NAME

ProductOpener::Text - formats decimal numbers and percentages according to locale.

SYNOPSIS

ProductOpener::Text is used to format decimal numbers and percentages according to locale.

        use ProductOpener::Text qw/:all/;
        
        my $decf = get_decimal_formatter($lc);
        my $perf = get_percent_formatter($lc, 0);
        $salt = $decf->format(g_to_unit($salt, $unit));
        $percent = $perf->format($percent / 100.0);

DESCRIPTION

The module implements decimal formatting, percent formatting and normalization of percentages on the basis of locale. Different languages can have different representation for decimal sign and can have different positions for the placement of percent in a value. The decimal sign could be a '.' (most languages), or it could be a ',' (de - DECIMAL POINT IS COMMA ;-)

FUNCTIONS

normalize_percentages( TEXT, LOCALE )

normalize_percentages() returns formatted percentage value on the basis of locale since every language has different standards for writing percentage and decimal values.

Arguments

Two scalar variables text and locale are passed as arguments. Locale is two letter language code (ur for Urdu, de for German, en for English, etc)

Return values

The function returns a scalar variable that is the result of concatenation of regex, percentage formatting on locale basis. If text (scalar variable passed as argument) is not defined or percent sign is not found, the function simply returns the scalar variable text(passed as argument) for performance reasons.

get_decimal_formatter( LOCALE )

get_decimal_formatter() formats decimal numbers. It can parse and format decimal numbers in any locale. The formatting is locale sensitive. This function allows to control the display of leading and trailing zeros, grouping separators, and the decimal separator. Different languages can have different representation for decimal sign. The decimal sign could be a '.' (most languages), or it could be a ',' (de - DECIMAL POINT IS COMMA ;-)

Arguments

A scalar variable locale is passed as argument. Locale is two letter language code (ur for Urdu, de for German, en for English, etc)

Return values

The function returns a scalar variable that is formatted on the basis of locale.

escape_char( $s, $char )

Escape character $char in string $s

This is use in templates to say escape single quote or double quote for expressions displayed with single/double quotes (in json or HTML for example)

escape_single_quote_and_newlines( $s )

Escape single quotes in $s but also transform newlines to spaces

get_percent_formatter( LOCALE, MAXIMUM_FRACTION_DIGITS )

get_percent_formatter() formats percentages according to locale. The formatting is locale sensitive.

Arguments

A scalar variable locale and maximum_fraction_digits are passed as argument. Locale is two letter language code (ur for Urdu, de for German, en for English, etc) maximum_fraction_digits sets the maximum number of digits allowed in the fraction portion of a number.

Return values

The function returns a scalar variable of percentage value that is formatted by a locale-specific formatter.

<<