weird math
From: Andrew Gaffney (agaffney_at_skylineaero.com)
Date: 05/28/04
- Next message: Boon Chong Ang: "max number of data within an array"
- Previous message: May: "Parse out alphabetic characters"
- Next in thread: Angie Ahl: "Re: weird math"
- Reply: Angie Ahl: "Re: weird math"
- Reply: Jeff 'Japhy' Pinyan: "Re: weird math"
- Maybe reply: Wiggins D Anconia: "Re: weird math"
- Reply: John W. Krahn: "Re: weird math"
- Reply: Kevin Old: "Re: weird math"
- Reply: Paul Johnson: "Re: weird math"
- Reply: Rob Dixon: "Re: weird math"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 27 May 2004 22:31:08 -0500 To: beginners <beginners@perl.org>
I am writing a program to parse a CSV file downloaded from my bank. I have it
keep a running balance, but I'm getting a weird total. Apparently, -457.16 +
460.93 = 3.76999999999998. But when 20 is subtracted from that, I get -16.23.
There are no weird numbers like that in my input data. All numbers have no more
than 2 numbers after the decimal point. Here is my code:
#!/usr/bin/perl
do './money.pl';
# use strict and warnings is defined in money.pl
my $balance = 0;
print $cgi->header;
print "<html><body>\n";
print "<table>\n<tr><td width=100>Date</td><td width=60>Type</td><td
width=350>Description</td><td width=80>Withdrawl<td width=80>Deposit</td$
my $csvdata = parse_csv("/tmp/usbank.csv");
foreach(@{$csvdata}) {
print "<tr><td>$_->{date}</td><td>$_->{type}</td><td>$_->{descr}</td>";
if($_->{amount} > 0) {
print "<td><br></td><td>$_->{amount}</td>";
} else {
print "<td>$_->{amount}</td><td><br></td>";
}
$balance += $_->{amount};
print "<td>$balance</td></tr>\n";
}
print "</body></html>";
money.pl is an include file that contains the parse_csv() function which pulls
apart each line of the downloaded CSV and pushes it into an array as an
anonymous hash.
-- Andrew Gaffney Network Administrator Skyline Aeronautics, LLC. 636-357-1548
- Next message: Boon Chong Ang: "max number of data within an array"
- Previous message: May: "Parse out alphabetic characters"
- Next in thread: Angie Ahl: "Re: weird math"
- Reply: Angie Ahl: "Re: weird math"
- Reply: Jeff 'Japhy' Pinyan: "Re: weird math"
- Maybe reply: Wiggins D Anconia: "Re: weird math"
- Reply: John W. Krahn: "Re: weird math"
- Reply: Kevin Old: "Re: weird math"
- Reply: Paul Johnson: "Re: weird math"
- Reply: Rob Dixon: "Re: weird math"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|