Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6362749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:56:57+00:00 2026-05-24T23:56:57+00:00

This is the end part of a script that takes 4 days information, averages

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:56:58+00:00Added an answer on May 24, 2026 at 11:56 pm

    This is a rounding numerical 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)? :


    For the long explanation, see David Goldberg’s “What Every Computer
    Scientist Should Know About Floating-Point Arithmetic”
    (http://web.cse.msu.edu/~cse320/Documents/FloatingPoint.pdf).

    Internally, your computer represents floating-point numbers in binary.
    Digital (as in powers of two) computers cannot store all numbers
    exactly. Some real numbers lose precision in the process. This is a
    problem with how computers store numbers and affects all computer
    languages, not just Perl.

    perlnumber shows the gory details of number
    representations and conversions. To limit the number of decimal places
    in your numbers, you can use the printf or sprintf function.

    See Floating Point Arithmetic in perlop for more details.

    printf "%.2f", 10/3;
    my $number = sprintf "%.2f", 10/3;
    

    In other words, if this is an issue, round it using sprintf:

    $variance = sprintf '%.9f', $todays_latency - $average ;  # Rounded to 9 d.p.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to design this script that's supposed to be used as a part
I have this script that is a part of a bigger one. I have
I have this SQL change script that runs as part of my nant orchestrated
The end goal of this part of my project is to be able to
Strange problem happening where the end of these 2 blocks of code (this part:
This is the first time I am working for a front-end project that requires
So, this is the script that has very kindly been given to me as
I'm working on a python script that opens a logfile, writes specific information to
I'm writing a complex script that takes the XML backup of a Blogger blog
In the end this is gonna be a simple responsive slider. problems being the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.