This is the end part of a script that takes 4 days information,
averages the previous three days, then subtracts todays value from the average
to get the variance.
The first example is correct.
However the second example if you subtract 0.00299268 from 0.002997575 equals -0.000004895. However List::Util is listing it as -4.89499999999955e-06.
I need to get it in regular notation.
use List::Util qw/sum/;
$todays_latency = $ecp_average[0];
$sum = sum $ecp_average[1] + $ecp_average[2] + $ecp_average[3] + $ecp_average[4];
$average = $sum/$#ecp_average;
$variance = $todays_latency - $average ;
print "Todays listing is $todays_latency\n";
print "The Average is $average\n";
print "Todays Variance from the average is $variance\n";
print "\n";
foreach(@ecp_average){
print "$_\n";
}
print "\n";
@ecp_average = ();
}
Output
Eislnd1
Todays listing is 0.00376258
The Average is 0.004412365
Todays Variance from the average is -0.000649785
0.00376258
0.00371207
0.00511266
Eislnd2
Todays listing is 0.00299268
The Average is 0.002997575
Todays Variance from the average is -4.89499999999955e-06
0.00299268
0.00301986
0.00297529
This is a
roundingnumerical representation issue.From
perldoc perlfaq4 :Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)? :In other words, if this is an issue, round it using
sprintf: