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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:05:42+00:00 2026-06-01T16:05:42+00:00

First, we see the code below: result = 0.1 + 0.2; alert(result===0.3);// false result=100.1+100.2;

  • 0

First, we see the code below:

result = 0.1 + 0.2;     
alert(result===0.3);// false
result=100.1+100.2;
alert(result===200.3);//true

I believe that 0.1 and 100.1 (100+0.1) are stored similarly in memory, since the decimal is .1 in both of them.

So, why is the result of the addition different?

  • 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-06-01T16:05:43+00:00Added an answer on June 1, 2026 at 4:05 pm

    They are not stored the same in memory: http://steve.hollasch.net/cgindex/coding/ieeefloat.html

    0.1 in binary:

    0.1 * 2 = 0 + 0.2
    0.2 * 2 = 0 + 0.4
    0.4 * 2 = 0 + 0.8
    0.8 * 2 = 1 + 0.6
    0.6 * 2 = 1 + 0.2
    0.2 * 2 = 0 + 0.4
    0.4 * 2 = 0 + 0.8
    0.8 * 2 = 1 + 0.6
    0.6 * 2 = 1 + 0.2

    As you can see, after the 0.2 repeated the whole pattern (0011) will just keep repeating, so 0.1 is 0.0001100110011001100110011... repeating forever

    To represent that in a 23 bit mantissa we have to shift it left until we have a 1 before the decimal point (after shifting the bits left 4 places and removing the 1 before the decimal we have 100110011...) and then round at the 23rd bit, and we get: 10011001100110011001101.

    Since we shifted 4 places our exponent is 127-4 (127 is the 32 bit bias). 123 in 8 bits of binary is 01111011, all that’s left is the sign bit, which we know is 0 since 0.1 is a positive number. So each component of the 32 bit binary number is:

    sign: 0
    exponent: 01111011
    mantissa: 10011001100110011001101

    0.1 is represented as 00111101110011001100110011001101 in a floating point number.

    Converting back we have to break it back apart and then convert the exponent back to a decimal integer (123). We shift the mantissa (with an assumed 1 in front) to the right (127 – 123 = 4) times and get : 0.00011001100110011001101101 then we convert this back to decimal:

    0*1/2 + 0*1/4 + 0*1/8 + 1/16 + 1/32 + 0*1/64 + 0*1/128 + 1/256 + 1/512 + 
    0 + 1/4096 + 1/8192 + 0 + 1/65536 + 1/131072 + 0 + 1/1048576 + 1/2097152 + 
    0 + 1/16777216 + 1/33554432 + 0 + 1/134217728
    

    Which if you do the math gives you something closer to 0.100000001, than to 0.1. That’s because we rounded at the 23rd bit. 0.1 cannot be stored in binary since it repeats forever, so after the 23rd bit we have inaccuracies. When you do arithmetic on a number those inaccuracies are carried through, and the errors can grow to be much larger.

    If you do the same thing with 100.1 you get:

    1100100.0001100110011001100… repeating forever:

    Shift right 6 times and removing the 1 before the decimal round to 23rd bit: 10010000011001100110011

    Exponent is 127+6 = 133 (1000 0101)

    Sign is 0 again, so you have:

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

Sidebar

Related Questions

Given my code below, is there a way that the first WebTestingApp constructor can
First let me say that I did see this article: How to remove AspxAutoDetectCookieSupport
I need a jquery script section that checks to see if the first digit
Delphi XE. Windows 7. There is a function (please see a code below) or
It is not the first time i see it Ive seen in Facebook source
I'm just taking my first steps with Azure and the first thing I see
I'm familiarizing myself with Ruby and it's the first time I see synonyms for
Please see following examples first, and which one is better? Could you compare some
I see time.clock() on Windows 'starts' a timer when called for the first time,
First, a screenshot: As you can see, the tops of the shadows look OK

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.