Skip to content

Latest commit

 

History

History
52 lines (32 loc) · 1.03 KB

format_numbers.md

File metadata and controls

52 lines (32 loc) · 1.03 KB

Format Numbers

For formatting numbers in Perl in respect to locale for example for currencies, the CPAN distribution can be of help.

In Denmark the thousand separator is ., which is the decimal separator in USA.

And vice-verse the , is the decimal separator in Denmark and the thousand separator in USA.

use Number::Format;

my $number = 1234.5;

my $nf = new Number::Format(-thousands_sep   => '.',
                            -decimal_point   => ',');

print $nf->format_number($number);

exit 0;

Outputs:

1.234,5

And if you want to use USA notation.

use Number::Format;

my $number = 1234;

my $nf = new Number::Format(-thousands_sep   => ',',
                            -decimal_point   => '.');

print $nf->format_number($number);

exit 0;

Outputs:

1,234.5

Resources and References