The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Lingua::ITA::Numbers - Converts numeric values into their Italian string equivalents

VERSION

version 0.0682

SYNOPSIS

 # 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;

DESCRIPTION

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")

EXPORT

Nothing is exported by default. The following function is exported.

number_to_it($number,[options])

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

METHODS

The following method compose the OO interface to Lingua::ITA::Numbers.

Lingua::ITA::Numbers-new($number,[options])>

Creates and initialize an instance.

$obj->get_number

Returns the number contained in the instance.

$obj->get_string()

Returns the representation of the number as a string in Italian.

$obj->set_number($number)

Changes the number contained in the instance.

OPTIONS

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:

decimal

If different from zero is the minimal number of decimal places a number must have.

decmode

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.

name

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'.

OVERLOADING

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'.

METHODS

add =item clone =item convert_short =item convert_to_string =item div =item minus =item mult =item parse_num_string

SEE ALSO

Lingua::*::Numbers, overload.

BUGS

There is no control on options' values.

Decimals doesn't work correctly.

TODO

  • 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.

AUTHOR

Leo "TheHobbit" Cacciari, <hobbit@cpan.org>

Maintenance PetaMem <info@petamem.com>

COPYRIGHT AND LICENSE

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.