NAME

Math::Currency - Perl extension for performing exact currency math

SYNOPSIS

  use Math::Currency;
  $dollar = Math::Currency->new("$12,345.67");
  $taxamt = $dollar * 0.28;
  Math::Currency->format(
	{ 
		PREFIX    =>  '',
		SEPARATOR =>  ' ',
		DECIMAL   =>  ',',
		POSTFIX   =>  ' DM'
	});
  $deutschmark = Money(12345.67);

DESCRIPTION

Currency math is actually more closely related to integer math than it is to floating point math. Rounding errors on addition and subtraction are not allowed and division/multiplication should never create more accuracy than the original values. All currency values should round to the closest cent or whatever the local equivalent should happen to be.

This module employs Math::BigInt to perform its actual calculations (although I plan to change that to Bit::Vector soon), and has a flexible formatting scheme that should cover most formats in use worldwide. A currency value can have an individual format or the global currency format can be changed to reflect local usage. I used the suggestions in Tom Christiansen's PerlTootC to implement translucent attributes.

All common mathematical operations are overloaded, so once you initialize a currency variable, you can treat it like any number and get what you would expect.

AUTHOR

John Peacock <JPeacock@UnivPress.com>

SEE ALSO

perl(1).