Why are some simple sums coming out as exponential numbers Perl?

29 views Asked by At

I'm adding 4 simple numbers in 4 places. Yet the last one of the sequence, intead of adding up to zero, returns an exponential number:

There are 4 sections just like this, of which is is the last one:

# Data check rules #4
# add the values of remaining Col5 values, and see if it = 0
my $sum_col5 = 0;
for my $i (0 .. $#listOfValues){
    print $listOfValues[$i][5] . "\n";
    $sum_col5 += $listOfValues[$i][5];
}

The output for the values in the print statement looks like this just before they are added to sum from the array:

-1.52
0.80
0.05
0.67

If you add those numbers, they are 0. But when the $sum_col5 is printed to the screen at the end (or later in a report file), the number is:

1.11022302462516e-16%

I ran a converter on it and that translates to:

0.000000000000000111022302462516

The previous 3 sequences have 4 similar simple numbers and all add up fine.

What could be going wrong?

0

There are 0 answers