ePages 6.11.0 - DE_EPAGES/Core/API/Object/NumberFormat.pm

Package DE_EPAGES::Core::API::Object::NumberFormat

At first see 'perldoc Number::Format', this module is based on this CPAN module. Includes extensions like rounding (the Swiss centime) round and corrects the formatting of positive and negative currencies. See also the test script of this package Core/t/NumberFormat.t.

Base
Number::Format

Functions

ceiling
compare
format_price
new
round
roundTotal
unformat_number

ceiling

Round to ceiling.

Syntax
my $Ceil = $NumberFormat->ceiling($Number);
Input
$Number (float)
number in perl
Return
$Ceil (int)
rounded number

compare

Compares two float numbers (avoid numeric problems).

Syntax
$result = $Formatter->compare($Amount1, $Amount2);
Input
$Amount1 (float)
first float number
$Amount2 (float)
second float number
Return
$result (int)
0 if equal / -1 if smaller / 1 if greater / undef if one is no float number

format_price

Rounds and formats the number to an currency string

Syntax
my $Formatted = $NumberFormat->format_price($Number, $Precision);
Input
$Number (float)
number in perl
$Precision (int)
number of decimal digits (default option decimal_digits of new)
Return
$Formatted (string)
formatted number

new

Creates new formatter/unformatter.

Syntax
my $NumberFormat = DE_EPAGES::Core::API::Object::NumberFormat->new(%options);
Input
%options (hash)
options of formatter, keys:
  • curr_pos_format - positive currency format (default '¤x') - string
  • curr_neg_format - negative currency format (default '-¤x') - string
  • int_currencyid - international currency identifier (optional) - char(3)
  • thousands_sep - character inserted between groups of 3 digits
  • decimal_point - character separating integer and fractional parts
  • mon_thousands_sep - like THOUSANDS_SEP, but used for format_price
  • mon_decimal_point - like DECIMAL_POINT, but used for format_price
  • int_curr_symbol - character(s) denoting currency (see format_price())
  • decimal_digits - number of digits to the right of dec point (default: 10)
  • decimal_fill - boolean; whether to add zeroes to fill out decimal
  • neg_format - format to display negative numbers (def ``-x'')
  • kilo_suffix - suffix to add when format_bytes formats kilobytes
  • mega_suffix - " " " " " " megabytes
  • giga_suffix - " " " " " " gigabytes
Return
$NumberFormat (object)
formatter object

round

Round the number.

Syntax
my $Rounded = $NumberFormat->round($Number, $Precision);
Input
$Number (float)
number in perl
$Precision (int)
number of decimal digits (default option decimal_digits of new)
Return
$Rounded (int)
rounded number | float

roundTotal

Round the number. Round to 0 or 5 an decimal value for currency CHF.

Syntax
my $Rounded = $NumberFormat->roundTotal($Number, $Precision);
Input
$Number (float)
number in perl
$Precision (int)
number of decimal digits (default option decimal_digits of new)
Return
$Rounded (int)
rounded number | float

unformat_number

Picks up the digits of an currency string.

Syntax
my $Number = $NumberFormat->unformat_number($Formatted);
Input
$Formatted (string)
formatted number
Return
$Number (float)
number in perl