Skip to content

lokku/Number-Format-SouthAsian

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

Number::Format::SouthAsian - format numbers in the South Asian style

SYNOPSIS

Formats numbers in the South Asian style. You can read more on Wikipedia here:

http://en.wikipedia.org/wiki/South_Asian_numbering_system

The format_number() method has a words parameter which tells it to use words rather than simply separating the numbers with commas.

my $formatter = Number::Format::SouthAsian->new();
say $formatter->format_number(12345678);             # 1,23,45,678
say $formatter->format_number(12345678, words => 1); # 1.2345678 crores

You can also specify words to new(), which has the effect of setting a default value to be used.

my $formatter = Number::Format::SouthAsian->new(words => 1);
say $formatter->format_number(12345678);             # 1.2345678 crores
say $formatter->format_number(12345678, words => 0); # 1,23,45,678

You can also specify "decimals" to either new() or format_number(), which has the effect of rounding any decimals found. Note that this means slightly different things depending on wordiness.

my $rounding_formatter = Number::Format::SouthAsian->new(decimals => 2);
say $rounding_formatter->format_number(1234.5678); # 1,234.57
say $rounding_formatter->format_number(12345678, words => 1); # 1.23 crores

In India it is common to use lakhs and crores, but quite uncommon to see any of the other larger number names. An "arab" is much more likely to be called "100 crores" and a "kharab" is more likely to be called a "lakh crore." This behaviour can be enabled with the lakhs_and_crores_only parameter.

my $lakhs_and_crores_only_formatter = Number::Format::SouthAsian->new(words => 1, lakhs_and_crores_only => 1);
say $lakhs_and_crores_only_formatter->format_number(1_00_00_00_000); # 100 crores

Copyright

Copyright (C) 2010 Lokku Ltd.

Author

Alex Balhatchet (alex@lokku.com)

About

provides methods to format numbers in the South Asian style

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages