Math::Currency uses the following formula to calculate "as_int()":
sub as_int {
my $self = shift;
return Math::BigInt->new(
$self->as_float * 10**$self->format()->{FRAC_DIGITS} )->bstr;
}
This introduces errors if the number of digits is not the expected "2
digits" and the currency cannot be changed to lowest denominator with a
simple exponential function.
For example, this would fail if:
* You made a locale where FRAC_DIGITS were 3
* You made a locale where 1 pound is 12 shillings
Note: this problem isn't solved by declaring the default currency to be
US as one could, conceivably want to store more than 2 FRAC_DIGITS.
This program demonstrates the problem:
---
#!/usr/bin/perl
use Math::Currency;
Math::Currency->format("INT_FRAC_DIGITS", 3);
Math::Currency->format("FRAC_DIGITS", 3);
my $m = Math::Currency->new("1.003");
print $m->as_int();
=pod
=head1 SYNOPSIS
"as_int()" reports incorrect value when *FRAC_DIGITS is not 2.
=head1 HOW TO REPEAT
=over
=item *
Run this code and the value returned will be "1003"!
=back
=cut