On 20090508 00:23, ccc31807 <(EMail Removed)> wrote:
> On May 7, 5:48*pm, bobmct <(EMail Removed)> wrote:
>> The report file in question has about 13 columns of financial amounts
>> such as 1,234,567.89 and I wish to extract each column and output to
>> a record in a signed, efficient format for later use by these other
>> perl programs.
>
> It's not clear to me exactly how you want your output, but assuming
> that it's a signed float and all you need to do is delete the commas,
> this will do it:
> $c1 =~ s/,//g;
For monetary values, you often want to store the amount in the smallest
denomination. So 1,234,567.89 should be stored as 123456789 cents, not
as 1234567.89 Dollars. The reason for this is that decimal fractions
cannot be represented exactly in binary, so the amount is rounded to the
nearest multiple of a power of two (which happens to be
1234567.88999999989755451679229736328125 in this case).
If the amounts are always given with two digits after the decimal point,
you can just strip the decimal point, too:
$c1 =~ s/[,.]//g;
or
$c1 =~ tr/.,//d;
If the number of digits after the decimal point varies, you need to
normalize them first. Be careful!
hp
