Lingua::ITA::Numbers - Converts numeric values into their Italian string equivalents
version 0.0682
# Procedural Style use Lingua::ITA::Numbers qw(number_to_it); print number_to_it(315); # prints trecentoquindici print number_to_it(325.12) # prints trecentoventicinque virgola dodici print number_to_it(325.12,decmode => 'fract') # prints trecentoveticinque e dodici centesimi # OO Style use Lingua::ITA::Numbers; my $number = Lingua::ITA::Numbers->new( 123 ); print $number->get_string; print $number->get_ordinate;
Number 2 Word conversion in ITA.
Lingua::ITA::Numbers converts arbitrary numbers into human-oriented Italian text. The interface is sligtly different from that defined for Lingua::EN::Numbers, for one it can be used in a procedural way, just like Lingua::FR::Numbers, importing the number_to_it function.
Remark that Lingua::ITA::Numbers object, created by the new constructor described below, are Two-face scalars as described in overload: when a Lingua::ITA::Numbers object is used as a number, then it is a number, when it is used as a string then it is its Italian representation (see "OVERLOADING")
Nothing is exported by default. The following function is exported.
Converts a number to its Italian string representation without building the Lingua::ITA::Numbers instance.
$string = number_to_it($number,...);
is equivalent to
$string = do { my $tmp = Lingua::ITA::Numbers->new($number,...); $tmp->get_string(); };
See "OPTIONS" for avalaible options for number_to_it
The following method compose the OO interface to Lingua::ITA::Numbers.
Creates and initialize an instance.
Returns the number contained in the instance.
Returns the representation of the number as a string in Italian.
Changes the number contained in the instance.
The representation of numbers by Lingua::ITA::Numbers can be influenced by means of options. Options are given either to the exported funcion number_to_it or to the constructor b<new> as named parameters. the following options are defined:
If different from zero is the minimal number of decimal places a number must have.
Can be either normal or fract. This options selects the method used for writing the fractional part of a number. Infact, in Italian there are two way to represent fractional numbers in writing. For 345.27 you can say either "trecentoquarantacinque virgola ventisette" or "trecentoquarantacinque e ventisette centesimi". The latter is used mainly for mensurament. Setting the decmode option to normal (its default value) selects the former method, while setting it to fract selects the latter.
The value of this option can be either a string or (a reference to) an array containing two strings. If the option value is a string this is interpolated between the integer part and the fractional part. If the option value is an array, the first element is taken to be the singular form while the second is the plural. So that
my $euro = Lingua::ITA::Numbers->new(253,name => "euro", decmode => 'fract', decimal => 2); print $euro->get_string(),"\n"
will print 'duecentocinquantatre euro e zero centesimi', while
my $dollar = Lingua::ITA::Numbers->new(253,name => [qw(dollaro dollari)], decmode => 'fract', decimal => 2); print $dollar->get_string(),"\n"
will print 'duecentocinquantatre dollari e zero centesimi'.
As stated above, instances of Lingua::ITA::Numbers are Two-face scalars like those described in overload. This means that you can do something like:
my $first = Lingua::ITA::Numbers->new(123); my $second = Lingua::ITA::Numbers->new(321); print $first,' + ',$second,' = ',$first+$second,"\n";
which will print: 'centoventitre + trecentoventuno = quattrocentoquarantaquattro'.
Lingua::*::Numbers, overload.
There is no control on options' values.
Decimals doesn't work correctly.
Add italian documentation
Add a package Lingua::ITA::Number::Currency for handling monetary values
Check an italian grammar to verify that what I remember from primary school about number writing hasn't changed.
Leo "TheHobbit" Cacciari, <hobbit@cpan.org>
Maintenance PetaMem <info@petamem.com>
Copyright (C) 2004 by Leo "TheHobbit" Cacciari
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available.
To install Lingua::ITA::Numbers, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Lingua::ITA::Numbers
CPAN shell
perl -MCPAN -e shell install Lingua::ITA::Numbers
For more information on module installation, please visit the detailed CPAN module installation guide.