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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:40:40+00:00 2026-05-23T18:40:40+00:00

I ran into this issue the other day and couldn’t figure out what exactly

  • 0

I ran into this issue the other day and couldn’t figure out what exactly is happening under the hood. What are the rules for coercion of a String into a Number type? and why does it fail in the instance of ‘5.0.1’?

var numStr = '5.0';
var floatStr = '5.0.1';

//Passes
if (numStr >= 4) {
    alert('5 > 4');
}

//Fails
if (floatStr >= 4) {
    alert('5.0.1 > 4');
}

console.log(parseInt(numStr)); //5
console.log(parseInt(floatStr)); //5

console.log(Number(numStr)); //5
console.log(Number(floatStr)); //NaN
  • 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-23T18:40:41+00:00Added an answer on May 23, 2026 at 6:40 pm

    Well, for one, "5.0.1" is not a valid String representation of a floating pointer number. I would have expected parseInt to have failed as well.

    Edit: However, as opposed to type casting the value, parseInt is a function that was designed to extract a value with more tolerance for noise.

    The particular implementation details are defined in: EMCA-262

    For instance, when applying a cast Number([value]), the toNumber function is used to perform the conversion — described in section 9.3.1. The behavior of parseInt is described in section 15.1.2.2.

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

Sidebar

Related Questions

I ran into this issue while testing a rails app deployed to two different
I just ran into this issue while making a GET request to a node.js
I've ran into trouble with SOAP, I've never had this issue before and can't
I ran into this issue quite a few times. Let's say I have a
Ran into this issue yesterday on one of our sites. First of all the
I ran into this issue twice now, and am curious to know if there
I ran into this interesting issue today. I have a button on a wpf
Ran into this error message while trying to select some records off a table.
I ran into this error when building my code with CLANG: In file included
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {

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.