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

NAME

Finance::Currency::ParValueSeparate - give least number of every parvalue within a certain amount

SYNOPSIS

 # create new object to resolve RMB 317 needs which least number of parvalue
 use Finance::Currency::ParValueSeparate;
 my $pvs = new Finance::Currency::ParValueSeparate( RMB => 317 );
 $pvs->parse;

 # list all parvalue which we need and how many we need
 map { print "parvalue \$$_: ", $pvs->number_of_dollar($_), "\n" } $pvs->dollar_parvalues;

more flexible usage see the method part below.

DESCRIPTION

When we offer salaies to employees with cash, we should prepare some different parvalue of money. For example, we pay $327 to a guy, we should prepare three $100 parvalue and one $20 parvalue and one $5 parvalue and two $2 parvalue. Of course it's easy for a man to decide how many and which parvalue we need to pay, and in my later project, the customer often parepare salaies for a group of employees, so many person's salaies we should compute then let perl take it over, and further more, the customer only want know totally how many every parvalue he should prepare to pay the group. Here this module comes.

METHODS

new()
 my $pvs = new Finance::Currency::ParValueSeparate( currency => 'RMB' );

only giving the currency type, here is RMB, so inside the module, it will return a Finance::Currency::ParValueSeparate::RMB object. here no amount given, so the amount is 0.

 my $pvs = new Finance::Currency::ParValueSeparate( RMB => 317.34 );

here we also giving the currency type and the amount to be parse.

 my $pvs = new Finance::Currency::ParValueSeparate( RMB => ['317.34','512.14'] );

the amount could be an array, so later we can know the totally how many different parvalue we need for all items in the amount array after parsed.

 use Finance::Currency::ParValueSeparate::RMB;
 my $pvs = new Finance::Currency::ParValueSeparate::RMB(); # amount is 0
 my $pvs = new Finance::Currency::ParValueSeparate::RMB( 317.34 );
 my $pvs = new Finance::Currency::ParValueSeparate::RMB( 317.34, 512.14 );
 my $pvs = new Finance::Currency::ParValueSeparate::RMB( ['317.34','512.14'] );

of course, we can directly use the subclass. here we already know which currency we use, so just tell it the amount we need to parse.

amount()
 # set the amount
 $pvs->amount( 852.50 );
 $pvs->amount( 852.50, 512.14 );

 # get the amount
 my $amount = $pvs->amount; # return array ref for amount list
 my @amount = $pvs->amount; # return array for amount list

the amount value will format as %.2f.

with_dollar(), without_dollar()

may be we has no $20 and $5 to prepare, so we should figure that, let parser skip that parvalues. so you can using:

 $pvs->without_dollar(qw(20 5));
 $pvs->without_dollar([20, 5]);

vice verser, if we only have $20 and $10 parvalue, we shoulg using:

 $pvs->with_dollar(qw( 20 10 ));
 $pvs->with_dollar([20, 10]);

if no array passed, just return present value. when set with_dollar([...]) you can call without_dollar() for return the skipped parvalues, and vice verser.

you should either use with_dollar(...) or without_dollar(...), if you invoke them multi-times, only the last setting call takes the final effect, all before setting will seems nothing.

with_cent(), without_cent()

same as above, but here we specified the cent(or penny, anyway, the float part of an amount) parvalue to with or without.

 $pvs->with_cent(qw( 45 25 ));
 $pvs->without_cent(qw( 5 1 ));
only_dollar()

sometimes we only need parse the dollar part, and ignore the float part.

 $pvs->only_dollar(1); # ignore cent part to parse
 $pvs->only_dollar(0); # within cent part to parse
 $pvs->only_dollar(); # return boolen
parse()
 $pvs->parse(); # using $pvs->amount to parse
 $pvs->parse( 314.34 ); # just parse this amount
 $pvs->parse( @amount_list );
dollar_parvalues(), cent_parvalues()
 my @parvalues = $pvs->dollar_parvalues();
 my @parvalues = $pvs->cent_parvalues();

return a list for which parvalue we need prepare

number_of_dollar(), number_of_cent()
 my $number = $pvs->number_of_dollar(50);
 my $number = $pvs->number_of_cent(25);

return how many the certain parvalue we need prepare

AUTHOR

Chun Sheng <me@chunzi.org>

COPYRIGHT

Copyright (c) 2000-2002 Matthew P. Sisk. All rights reserved. All wrongs revenged. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 202:

'=item' outside of any '=over'

Around line 287:

You forgot a '=back' before '=head1'