The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
[Originally posted by ralphie]

Can't get the following to balance i.e. the total of all line_items once
converted is different to the converted invoice total. Is there a solution?
Maybe I don't need Math::BigFloat. The amounts are all in pennies.

sub convert {
use Math::BigFloat;

my %currency_conv_hash = (IEP=>"EUR",GBP=>"GBP",USD=>"USD",EUR=>"EUR",
ITL=>"EUR", ATS=>"EUR", BEF=>"EUR", PTE=>"EUR" );

my %rate_hash = (IEP=>".787564",GBP=>"1",USD=>"1",EUR=>"1", FFR=>"6.55957",
NLG=>"2.20371", ESP=>"166.386", DEM=>"1.95583",
ITL=>"1936.27", ATS=>"13.7603", BEF=>"16.11", PTE=>"200.482" );

my ($source_currency, $unconverted_amount, $unconverted_total_amount) = @_;
my $rate=$rate_hash{$source_currency};
my $line_amount = Math::BigFloat->new($unconverted_amount/$rate);
my $total_amount = Math::BigFloat->new($unconverted_total_amount/$rate);
return ($currency_conv_hash{$source_currency}, (sprintf
",$line_amount->fround(0)), (sprintf "%.0f

import-bot (20211) [Avatar] Offline
Re: Rounding problems
[Originally posted by dave]

Floating point numbers in computers are inherently imprecise. You can't
guarantee that calculations like to ones you're doing will balance - it's all
to do with the way that floating point numbers are stored.

Sorry smilie