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 3316798
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:30:42+00:00 2026-05-17T22:30:42+00:00

In perl, I want to check if the given variable holds a floating point

  • 0

In perl, I want to check if the given variable holds a floating point number of not. To check this I am using,

my $Var = 0.02 # Floating point number

if (int($Var) != $Var) {

   # floating point number
}

But the above code will not work for 0.0,

How can I achieve this?

  • 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-17T22:30:43+00:00Added an answer on May 17, 2026 at 10:30 pm

    This is a FAQ. See How do I determine whether a scalar is a number/whole/integer/float?

    You can also use Scalar::Util::Numeric.

    Interestingly, while

    #!/usr/bin/perl
    
    use strict; use warnings;
    use Scalar::Util::Numeric qw(isint);
    
    my $x = 0.0;
    print "int\n" if isint $x;
    

    prints int (not surprising if you look at the source code), based on @tchrist’s comment, it should be possible to look at the information supplied in the variables structure to distinguish 0 from 0.0:

    #!/usr/bin/perl
    
    use strict; use warnings;
    use Devel::Peek;
    
    my $x  = 0.0; print Dump $x;
    my $y  = 0;   print Dump $y;
       $y *= 1.1; print Dump $y;
    

    Output:

    SV = NV(0x18683cc) at 0x182c0fc
      REFCNT = 1
      FLAGS = (PADMY,NOK,pNOK)
      NV = 0
    SV = IV(0x182c198) at 0x182c19c
      REFCNT = 1
      FLAGS = (PADMY,IOK,pIOK)
      IV = 0
    SV = PVNV(0x397ac) at 0x182c19c
      REFCNT = 1
      FLAGS = (PADMY,NOK,pNOK)
      IV = 0
      NV = 0
      PV = 0

    It seems to me that the check would have to just look at if the NOK flag is set. It takes me ages to write even the simplest XS so I won’t provide an implementation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ActiveState Perl on Windows Server 2003. I want to create a directory
I want to check the results of an operation in the Net::FTP Perl module
I want to use the perl to check the hard disk space on Windows
How to check if today is a weekend using bash or even perl? I
I want to use Perl to extract information from a Certificate Signing Request ,
I want to wrap a Perl one-liner in a batch file. For a (trivial)
I want to use regular expressions (Perl compatible) to be able to find a
I want to integrate some existing Perl code with ASP.NET. I see plenty examples
I want to maintain state in my Perl web app. How can I do
I want another developer to run a Perl script I have written. The script

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.