Number::Format::Calc
use Number::Format::Calc (%args); $n = new Number::Format::Calc ('1.234,5', %args );
This module makes calculations with formatted numbers transparent.
All arithmetric operators and and some arithmetric functions (sqrt, abs, cos, sin, exp, log) are overloaded.
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.
use Number::Format::Calc (%args);
This method returns the number without formats.
This method returns the result of a floating-point modulo operation from $self->number modulo $foo.
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
Number::Format Test::Simple
None that I know of. If you find one, or a missing test-case, let me know.
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
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.
perl(1).
To install Number::Format::Calc, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Number::Format::Calc
CPAN shell
perl -MCPAN -e shell install Number::Format::Calc
For more information on module installation, please visit the detailed CPAN module installation guide.