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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:59:52+00:00 2026-05-12T08:59:52+00:00

How can I test a variable to ascertain if it contains a number, and

  • 0

How can I test a variable to ascertain if it contains a number, and it is an integer?

e.g.

if (1.589 == integer) // false
if (2 == integer) // true

Any clues?

  • 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-12T08:59:52+00:00Added an answer on May 12, 2026 at 8:59 am
    num % 1 === 0
    

    This will convert num to type Number first, so any value which can be converted to an integer will pass the test (e.g. '42', true).

    If you want to exclude these, additionally check for

    typeof num === 'number'
    

    You could also use parseInt() to do this, ie

    parseInt(num) == num
    

    for an untyped check and

    parseInt(num) === num
    

    for a typed check.

    Note that the tests are not equivalent: Checking via parseInt() will first convert to String, so eg true won’t pass the check.

    Also note that the untyped check via parseInt() will handle hexadecimal strings correctly, but will fail for octals (ie numeric strings with leading zero) as these are recognized by parseInt() but not by Number(). If you need to handle decimal strings with leading zeros, you’ll have to specify the radix argument.

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

Sidebar

Related Questions

In PowerShell, how can I test if a variable holds a numeric value? Currently,
Is there a way I can test if there are any other activities in
I am wondering is there any way we can test the font size/color of
Can you test touchEvent on Adobe Device Cental, google it can't find any information.
Windows user defined environment variable names can contain any character except = . Special
how can I test if a dynamic variable is a double for example? I
Question Although you can explicitly check if a value is true or false, it's
Is there any way in which you can test whether an instance of a
How can I test wether a variable has been declared or assigned (i.e. check
Is it possible to set number of test runs variable on TFS 2010 build

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.