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

NAME

Number::Format::Calc

SYNOPSIS

 use Number::Format::Calc (%args);
 $n = new Number::Format::Calc ('1.234,5', %args );

DESCRIPTION

This module makes calculations with formatted numbers transparent.

All arithmetric operators and and some arithmetric functions (sqrt, abs, cos, sin, exp, log) are overloaded.

METHODS

new ($self, $number, %args)

The constructor awaits the formatted number-string as the first argument, and a hash with the same formatting-options as in Number::Format.

The same arguments can be passed via the use Number::Format::Calc (%args);-statement and will then serve as defaults for all instances of Number::Format::Calc-objects.

number ($self)

This method returns the number without formats.

fmod ($self, $foo)

This method returns the result of a floating-point modulo operation from $self->number modulo $foo.

Examples

 use Number::Format::Calc;

 my $n = new Number::Format::Calc ( '1.111,5'  , -thousands_sep=>".", -decimal_point=>",", decimal_digits=>1 );
 my $m = new Number::Format::Calc ( '2.222,35' , -thousands_sep=>".", -decimal_point=>",", decimal_digits=>2 );

 #add 10 to the object
 print $n + 10, "\n"; #1.121,5;

 #When two objects are involved, the settings of the left object win:
 print $n + $m, "\n"; #3.333,9;
 print $m + $n, "\n"; #3.333,85;

 #modulo operation
 print $n % 9, "\n"; #4

 #floating-point modulo operation
 print $n->fmod(9), "\n"; #4.5

 #Get plain number
 print $n->number; #1111.5

More examples can be found in the test-files (*.t) that come with this module.

 ########################################################################

 #using defaults
 use Number::Format::Calc ( -thousands_sep=>".", -decimal_point=>",", -decimal_digits=>2, -decimal_fill => 1 );

 my $n = new Number::Format::Calc ('1.111,5');
 print $n; #1.111,50

PREREQUISITIES

 Number::Format
 Test::Simple

BUGS

None that I know of. If you find one, or a missing test-case, let me know.

AUTHOR

 Markus Holzer
 CPAN ID: HOLLIHO
 HOLLIHO@gmx.de
 http://holli.perlmonk.org

You can also reach me via the chatterbox at http://www.perlmonks.org

COPYRIGHT

This program is free software licensed under the...

    The General Public License (GPL)
    Version 2, June 1991

The full text of the license can be found in the LICENSE file included with this module.

SEE ALSO

perl(1).