Lingua-RO-Numbers
view release on metacpan or search on metacpan
- Removed the usage of the deprecated 'encoding' pragma.
0.11 2013-03-15
- Added kwalitee test.
- Converted releases dates to W3CDTF.
- Added META.yml file.
0.10 2013-03-13
- Added support for Object-Oriented functionality.
- Added support for customizable options.
- Fixed deep-recursion for number which is, actually, "NaN".
- Added support for 'inf'.
- Doesn't returns a list in list context, but a string.
0.09 2013-02-14
- Added 'encoding' to dependencies in Build.PL
0.08 2013-02-08
- Great unification:
Joined the code for floating points smaller than zero,
with the code for floating points greater than zero.
is equivalent with:
```perl
my $obj = Lingua::RO::Numbers->new(
diacritics => 1,
invalid_number => undef,
negative_sign => 'minus',
decimal_point => 'virgulÄ',
thousands_separator => '',
infinity => 'infinit',
not_a_number => 'NaN',
);
```
#### `number_to_ro($number)`
Converts a number to its Romanian string representation.
```perl
# Functional oriented usage
$string = number_to_ro($number);
lib/Lingua/RO/Numbers.pm view on Meta::CPAN
is equivalent with:
my $obj = Lingua::RO::Numbers->new(
diacritics => 1,
invalid_number => undef,
negative_sign => 'minus',
decimal_point => 'virgulÄ',
thousands_separator => '',
infinity => 'infinit',
not_a_number => 'NaN',
);
=item B<number_to_ro($number)>
Converts a number to its Romanian string representation.
# Functional oriented usage
$string = number_to_ro($number);
$string = number_to_ro($number, %opts);
lib/Lingua/RO/Numbers.pm view on Meta::CPAN
sub new {
my ($class, %opts) = @_;
my $self = bless {
diacritics => 1,
invalid_number => undef,
negative_sign => 'minus',
decimal_point => 'virgulÄ',
thousands_separator => '',
infinity => 'infinit',
not_a_number => 'NaN',
}, $class;
foreach my $key (keys %{$self}) {
if (exists $opts{$key}) {
$self->{$key} = delete $opts{$key};
}
}
foreach my $invalid_key (keys %opts) {
warn "Invalid option: <$invalid_key>";
lib/Lingua/RO/Numbers.pm view on Meta::CPAN
my $factor = 1; # int -- multiplication factor
if (@words) {
# Check for negative numbers
if ($words[0] eq $neg_sign) {
$neg = 1;
shift @words;
}
# Check for infinity and NaN
if (@words == 1) {
# Infinity
my $inf = _normalize_text($self->{infinity});
if ($words[0] eq $inf) {
return $neg ? -9**9**9 : 9**9**9;
}
# Not a number
my $nan = _normalize_text($self->{not_a_number});
lib/Lingua/RO/Numbers.pm view on Meta::CPAN
# This function converts numbers
# into their Romanian equivalent text.
sub _number_to_ro {
my ($self, $number) = @_;
my @words;
if (exists $DIGITS{$number}) { # example: 8
push @words, $DIGITS{$number};
}
elsif (lc($number) eq 'nan') { # not a number (NaN)
return $self->{not_a_number};
}
elsif ($number == 9**9**9) { # number is infinit
return $self->{infinity};
}
elsif ($number < 0) { # example: -43
push @words, $self->{negative_sign};
push @words, $self->_number_to_ro(abs($number));
}
elsif ($number != int($number)) { # example: 0.123 or 12.43
( run in 0.364 second using v1.01-cache-2.11-cpan-05444aca049 )