[Chicago-talk] addition weirdness

Wiggins d Anconia wiggins at danconia.org
Thu Jan 29 09:45:39 CST 2004



> When I run :
> 
> #!/usr/bin/perl
> 
> $total = 0;
> while (<>) {
>   $total += $_;
> }
> print "$total\n";
> 
> with a file full of numbers (http://laughingman.net/numbers.txt) as 
> input I get 2752872.74999999.  Strangely the file only contains numbers 
> with two digits after the decimal point.  Other number lists (including 
> this same file without its last line) produce normal results.
> 
> Any idea why this is happening?
> 
> Whitney

perldoc -q decimal
http://www.perldoc.com/perl5.8.0/pod/perlfaq4.html#Why-am-I-getting-long-decimals-(eg%2c-19.9499999999999)-instead-of-the-numbers-I-should-be-getting-(eg%2c-19.95)-

HTH,

http://danconia.org





More information about the Chicago-talk mailing list