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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:01:55+00:00 2026-05-25T17:01:55+00:00

It feels like I am missing something obvious here. This has been asked a

  • 0

It feels like I am missing something obvious here. This has been asked a number of times – and the answer usually boils down to:

var num = 4.5;
num % 1 === 0; // false - 4.5 is a decimal

But, this fails for

var num = 1.0; // or 2.0, 3.0, ...
num % 1 // 0

Unfortunately, these doesn’t work either

num.toString() // 1
typeof num // "number"

I am writing a JavaScript color parsing library, and I want to process input differently if it is given as 1.0 or 1. In my case, 1.0 really means 100% and 1 means 1.

Otherwise, both rgb 1 1 1 and rgb 1 255 255 will be parsed as rgb 255 255 255 (since I am right now taking anything <= 1 to mean a ratio).

  • 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-25T17:01:56+00:00Added an answer on May 25, 2026 at 5:01 pm

    Those numbers aren’t actually decimals or integers. They’re all floats. The only real difference between 1 and 1.0 is the notation that was used to create floats of equal values.


    Edit: to help illustrate, consider:

    1 === 1.0; // true
    parseInt('1') == parseInt('1.0'); // true
    parseFloat('1') === parseFloat('1.0'); // true
    parseInt('1') === parseFloat('1'); // true
    // etc...
    

    Also, to demonstrate that they are really the same underlying data type:

    typeof(1); // 'number'
    typeof(1.0); // 'number'
    

    Also, note that ‘number’ isn’t unambiguous in JavaScript like it would be in other languages, because numbers are always floats.


    Edit 2: One more addition, since it’s relevant. To the best of my knowledge, the only context in JavaScript in which you actually have “real and true” integers that aren’t really represented as floats, is when you’re doing bitwise operations. However, in this case, the interpreter converts all the floats to integers, performs the operation, and then converts the result back to a float before control is returned. Not totally pertinent to this question, but it helps to have a good understanding of Number handling in JS in general.

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

Sidebar

Related Questions

I feel like I am missing something obvious here, but I can't seem to
I feel like I'm missing something blindingly obvious here, so low hanging fruit for
I'm feel like I'm missing something pretty obvious here, but I can't seem to
I feel like I'm missing something obvious here. I just wanted to try putting
I feel like I am missing something stupidly obvious here, I am trying to
I feel like I must be missing something completely obvious, but I don't see
I feel like this is easy but I am missing something... Using jQuery, I
I feel like this is a dumb question and I'm missing something, but I
I feel like this should be a no brainer, but clearly I'm missing something...
I might be missing something basic here, but I'm stumped on this error: model

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.