
Currency-appropriate formatting for numbers

use Data::Quantity::Finance::Currency;
print Data::Quantity::Finance::Currency->type('USD')->readable_value( $pennies );
$pennies = Data::Quantity::Finance::Currency->type('USD')->numeric_value( <STDIN> );

This module provides functions to convert between different representations of currency values. It does not (yet) actually handle any foreign currencies, conversions or multiple-currency environments, but I imagine it might, some day.
Integer values are used for internal representation of currency values to avoid floating-point vagaries. For US Dollars, this means that values are stored as an integer number of pennies.
Converts an integer value to a readable string.
For US Dollars, this includes 1 = $0.01> and 148290 = $1,482.90>.
Convert an externally-generated candidate value into an integer.
For US Dollars, this includes 1 = $0.01> and 148290 = $1,482.90>.
There are two internal representations:
An integer value containing the major and minor currency numbers.
148290
A list of the major and minor currency numbers; in the context of US currency, these would be the dollar and cent amounts.
( 1482, 90 )

The local currency symbol. Defaults to '$'.
The number of decimal places supported by the selected currency. Defaults to 2.
The decimal separator for the selected currency. Defaults to '.'.
A flag to indicate if decimals are shown in display string. Defaults to 1.
Converts a value in the integral storage format to a formatted display string.
Converts a value in the integral storage format to an editable decimal number.
Converts a value in the editable decimal number format to a storable integer.
Converts a value in the editable decimal number format to a formatted display string.
These functions take a value in the storage or update format and convert it to a list of major and minor currency numbers.
Accepts a dollar value (formatted or not) and returns a list of dollars and cents.
Provides appropriate zero-padding for the major and minor currency numbers.
Now invokes display_update.
Returns a value with a dollar sign, comma separated groups and appropriate decimal values.
Now invokes display_store.
Works as pretty_dollars above, but converts argument from an integer number of pennies.
Now invokes store_update.
Accepts a dollar value and returns an integer ammount of pennies.
Now invokes update_store.

This module is still somewhat disorganized; the interface is likely to change in future versions.

Copyright 1997, 1998 Evolution Online Systems, Inc.
You can use this software under the same terms as Perl itself.