NAME

Math::Currency - Exact Currency Math with Formatting and Rounding

SYNOPSIS

  use Math::Currency qw(Money);
  $dollar = Math::Currency->new("$12,345.67");
  $taxamt = $dollar * 0.28;
  # this sets the default format for all objects w/o their own format
  Math::Currency->format(
	{
		PREFIX      =>     '',
		SEPARATOR   =>    ' ',
		DECIMAL     =>    ',',
		POSTFIX     =>  ' DM',
		FRAC_DIGITS =>      2,
		GROUPING    =>      3,
	});
  $deutschmark = Money(12345.67);
  $deutschmark_string = Money(12345.67)->bstr();
  # or if you already have a Math::Currency object
  $deutschmark_string = "$deutschmark";

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.

Each 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. If you have set your locale values correctly, this module will pick up your local settings or US standards if you haven't.

All common mathematical operations are overloaded, so once you initialize a currency variable, you can treat it like any number and the module will do the right thing. This module is a thin layer over Math::BigFloat which is itself a layer over Math::BigInt. The module optionally exports a single function Money() which can be used instead of Math::Currency->new().

AUTHOR

John Peacock <jpeacock@rowman.com>

SEE ALSO

perl(1). perllocale Math::BigFloat