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

  • SEARCH
  • Home
  • 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 898263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:00:56+00:00 2026-05-15T15:00:56+00:00

I am very confused about how decimal numbers work in perl. I’m having trouble

  • 0

I am very confused about how decimal numbers work in perl. I’m having trouble multiplying an int with a double. Here’s what I have:

sub timeEstimate(){
$number = shift;
print "Number: $number\n";
$stuff = sprintf("%d", $number * $number * $number) * .2045;
print "stuff: $stuff\n";
$totalDownloads = $stuff + ($number * $number) + $number;
print "totalDownloads: $totalDownloads\n";
$secondPerFile = .4464;
print "secondPerFile: $secondPerFile\n";
$totalSeconds = ($totalDownloads * $secondPerFile);
print "totalSeconds: $totalSeconds\n";
$totalHours = ($totalSeconds / 3600);
print "totalHours: $totalHours\n";
return $totalHours;
}

But no matter what I try, even sprintf, I still can’t get $stuff to be anything but 0. Could someone explain how the system works?

UPDATE-Solved: Due to stupid self-inflicted mistake. I had

use integer; 

in the code. headdesk

  • 1 1 Answer
  • 1 View
  • 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-15T15:00:57+00:00Added an answer on May 15, 2026 at 3:00 pm

    Once variables have been declared and the prototype removed from the function, your code seems to work:

    use warnings;
    use strict;
    
    sub timeEstimate {
        my $number = shift;
        print "Number: $number\n";
    
        my $stuff = sprintf("%d", $number * $number * $number) * .2045;
        print "stuff: $stuff\n";
    
        my $totalDownloads = $stuff + ($number * $number) + $number;
        print "totalDownloads: $totalDownloads\n";
    
        my $secondPerFile = .4464;
        print "secondPerFile: $secondPerFile\n";
    
        my $totalSeconds = ($totalDownloads * $secondPerFile);
        print "totalSeconds: $totalSeconds\n";
    
        my $totalHours = ($totalSeconds / 3600);
        print "totalHours: $totalHours\n";
        return $totalHours;
    }
    
    timeEstimate 10;
    
    
    Number: 10
    stuff: 204.5
    totalDownloads: 314.5
    secondPerFile: 0.4464
    totalSeconds: 140.3928
    totalHours: 0.038998
    

    In Perl functions, you always need to declare your variables with the my keyword (which allocates a lexically scoped variable) otherwise you will run into problems. Using use warnings; use strict; at the top of every program will keep you from forgetting, and will also provide many useful diagnostic messages.

    The () prototype you have on the timeEstimate function is in error. It specifies that the timeEstimate function does not accept any arguments. Do not use Perl’s function prototypes until you know exactly why you need to be using them.

    Lastly, your use of sprintf is not needed. The line can be rewritten as:

    my $stuff = 0.2045 * ($number ** 3);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read many documents still very confused about HTTP Live Streaming . But
I am very confused about this... Here is an extract from my code.. float
I have the following html and I am very confused about the following: The
I have knowledge of both UIViewController and UINavigationController. But I am very confused about
I am very confused about how constructors work in JavaScript; despite using the language
I'm very confused about the whole user profile thing in drupal, hope someone can
Ok, I'm now very confused. After my last question had several people comment about
Very confused here, trying out the yuicompressor on a simple javascript file. My js
I'm very confused and am hoping someone might have had this problem and be
I am very confused. I have this lambda expression: tvPatientPrecriptionsEntities.Sort((p1, p2) => p1.MedicationStartDate .Value

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.