Re: weird math

From: Andrew Gaffney (agaffney_at_skylineaero.com)
Date: 05/28/04


Date: Fri, 28 May 2004 14:56:04 -0500
To: Kevin Old <kold@kold.homelinux.com>

Kevin Old wrote:
> On Thu, 2004-05-27 at 23:31, Andrew Gaffney wrote:
>
>>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:
>
> [...]
>
>> print "<td>$balance</td></tr>\n";
>
>
> Andrew,
>
> Try using this when you print out the $balance:
>
> printf "%.2f", $balance;
>
> You'll get 3.77.

I was going to use that for output, but I was just curious why it was happening
in the first place. I think all the other posts answered that question.

-- 
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548


Relevant Pages

  • weird math
    ... I am writing a program to parse a CSV file downloaded from my bank. ... keep a running balance, but I'm getting a weird total. ...
    (perl.beginners)
  • Re: weird math
    ... > I am writing a program to parse a CSV file downloaded from my bank. ... perldoc -q "long decimals" ...
    (perl.beginners)
  • Re: weird math
    ... On Thu, 2004-05-27 at 23:31, Andrew Gaffney wrote: ... > I am writing a program to parse a CSV file downloaded from my bank. ...
    (perl.beginners)
  • RE: how do modules work?
    ... Andrew Gaffney wrote: ... > I've been using Perl for about a year. ... I'm writing my own module that ... > contains some custom functions that I use a lot. ...
    (perl.beginners)
  • Re: Matching/replacing
    ... LoneWolf wrote: ... > I have to parse a big file and I do it line by line to keep stuff going ... The only potential problem that I see is that the ... Andrew Gaffney ...
    (perl.beginners)