NAME
Locale::Unicode::RBNF::DecimalFormat - Decimal pattern formatting for Locale::Unicode::RBNF
SYNOPSIS
use Locale::Unicode::RBNF::DecimalFormat;
my $st;
my $nf = Locale::Unicode::RBNF::DecimalFormat->new( '#,##0.##', $cldr->symbols( 'fr', 'latn' ), \$st );
die( $st ) if( $st );
say $nf->format( 1234.567 );
# 1 234,57
VERSION
v0.1.0
DESCRIPTION
Internal module. It implements the subset of ICU DecimalFormat that rule-based number formats use in their substitutions, such as #,##0, #,##,##0, 0.0 or #,##0.#.
Significant digits (@), exponents (E), rounding increments and currency symbols are not supported, and a pattern using them is rejected.
CONSTRUCTOR
new
my $nf = Locale::Unicode::RBNF::DecimalFormat->new( $pattern, $symbols, \$st );
Takes a decimal pattern, an hash reference of decimal format symbols, as returned by "symbols" in Locale::Unicode::RBNF::CLDR, and a scalar reference that receives an error status, and returns a new object.
The object is always returned. If the pattern cannot be parsed, or uses a feature that is not supported, the status is set to an error message, and the caller must check it.
METHODS
format
my $string = $nf->format( $number, $is_int );
Formats the number according to the pattern and the symbols, and returns the resulting string. The fraction digits are rounded half-even to the maximum number of fraction digits of the pattern, and the digits are those of the symbols' numbering system.
If $is_int is true, the number is taken as an integer, digit for digit, so that integers beyond 2^53 keep their precision; otherwise, the shortest decimal representation of the double that round-trips is used, as ICU DecimalQuantity does. NaN and infinity are formatted with the nan and infinity symbols.
parse
my $pp = { index => 0, error => -1 };
my $value = $nf->parse( $text, $pp );
Parses a number at the position $pp->{index} of the text, honouring the affixes, the grouping and decimal separators and the digits of the symbols, and returns its value. On success, the index is moved past the number; otherwise, it is left unchanged and $pp->{error} is set to the position of the error.
This method is provided by Locale::Unicode::RBNF::PP, and used by the pure Perl parsing engine.
set_symbols
$nf->set_symbols( $symbols );
Replaces the decimal format symbols, and applies the pattern again so that its affixes are localised with the new symbols. It returns the current object.
to_pattern
Returns the pattern given to "new".
SEE ALSO
Locale::Unicode::RBNF, Locale::Unicode::RBNF::CLDR
AUTHOR
Jacques Deguest <jack@deguest.jp>
COPYRIGHT & LICENSE
Copyright(c) 2026 DEGUEST Pte. Ltd.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.