A
Amer Neely
I've read the FAQ 'Why am I getting long decimals (eg, 19.9499999999999)
instead of the numbers I should be getting (eg, 19.95)?' and other
references, but am still confused by the results I'm getting.
#! /usr/bin/perl
BEGIN
{
open (STDERR,">>$0-err.txt");
print STDERR "\n",scalar localtime,"\n$0\n";
}
use strict;
use warnings;
unless ($#ARGV == 1)
{
print "Usage: calc subtotal shipping\n";
exit;
}
my $subtotal=$ARGV[0];
my $shipping=$ARGV[1];
#my $fuelfee = .1;
my $fuelfee = 10;
printf "%8.2f\n",$subtotal;
printf "%8.2f\n",$shipping;
printf "%8.2f\n",($shipping / $fuelfee); # when $fuelfee = 10
printf "%8.2f\n",($shipping / $fuelfee) + $shipping + $subtotal; # when
$fuelfee = 10
#printf "%8.2f\n",($shipping * $fuelfee); # when $fuelfee = .1;
#printf "%8.2f\n",(shipping * $fuelfee) + $shipping + $subtotal; # when
$fuelfee = .1
__END__
Subtotal: $ 185.63
Shipping: $ 24.15
Fuel Fee: $ 2.42
Total: $ 212.19
If you add the numbers above in your head or a calculator, you get 212.2.
So I'm confused why perl is out by a penny.
Is it related to the FAQ?
$fuelfee is being rounded up by perl from 2.415 to 2.42. But it appears
to be using 2.415 in the addition, to get 212.195 but then not rounding
that to 212.2.
--
Amer Neely
w: www.softouch.on.ca/
b: www.softouch.on.ca/blog/
Perl | MySQL programming for all data entry forms.
"We make web sites work!"
instead of the numbers I should be getting (eg, 19.95)?' and other
references, but am still confused by the results I'm getting.
#! /usr/bin/perl
BEGIN
{
open (STDERR,">>$0-err.txt");
print STDERR "\n",scalar localtime,"\n$0\n";
}
use strict;
use warnings;
unless ($#ARGV == 1)
{
print "Usage: calc subtotal shipping\n";
exit;
}
my $subtotal=$ARGV[0];
my $shipping=$ARGV[1];
#my $fuelfee = .1;
my $fuelfee = 10;
printf "%8.2f\n",$subtotal;
printf "%8.2f\n",$shipping;
printf "%8.2f\n",($shipping / $fuelfee); # when $fuelfee = 10
printf "%8.2f\n",($shipping / $fuelfee) + $shipping + $subtotal; # when
$fuelfee = 10
#printf "%8.2f\n",($shipping * $fuelfee); # when $fuelfee = .1;
#printf "%8.2f\n",(shipping * $fuelfee) + $shipping + $subtotal; # when
$fuelfee = .1
__END__
Subtotal: $ 185.63
Shipping: $ 24.15
Fuel Fee: $ 2.42
Total: $ 212.19
If you add the numbers above in your head or a calculator, you get 212.2.
So I'm confused why perl is out by a penny.
Is it related to the FAQ?
$fuelfee is being rounded up by perl from 2.415 to 2.42. But it appears
to be using 2.415 in the addition, to get 212.195 but then not rounding
that to 212.2.
--
Amer Neely
w: www.softouch.on.ca/
b: www.softouch.on.ca/blog/
Perl | MySQL programming for all data entry forms.
"We make web sites work!"