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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:21:58+00:00 2026-05-15T10:21:58+00:00

I have read most of the posts on here regarding floating point, and I

  • 0

I have read most of the posts on here regarding floating point, and I understand the basic underlying issue that using IEEE 754 (and just by the nature of storing numbers in binary) certain fractions cannot be represented. I am trying to figure out the following: If both Python and JavaScript use the IEEE 754 standard, why is it that executing the following in Python

.1 + .1

Results in
0.20000000000000001 (which is to be expected)

Where as in Javascript (in at least Chrome and Firefox) the answer is .2

However performing

.1 + .2

In both languages results in
0.30000000000000004

In addition, executing
var a = 0.3; in JavaScript and printing a results in
0.3

Where as doing a = 0.3 in Python results in 0.29999999999999999

I would like to understand the reason for this difference in behavior.

In addition, many of the posts on OS link to a JavaScript port of Java’s BigDecimal, but the link is dead. Does anyone have a copy?

  • 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-15T10:21:58+00:00Added an answer on May 15, 2026 at 10:21 am

    doing a = 0.3 in Python results in
    0.29999999999999999

    Not quite — watch:

    >>> a = 0.3
    >>> print a
    0.3
    >>> a
    0.29999999999999999
    

    As you see, printing a does show 0.3 — because by default print rounds to 6 or 7 decimal digits, while typing an expression (here a is a single-variable expression) at the prompt shows the result with over twice as many digits (thus revealing floating point’s intrinsic limitations).

    Javascript may have slightly different rounding rules about how to display numbers, and the exact details of the rounding are plenty enough to explain the differences you observe. Note, for example (on a Chrome javascript console):

    > (1 + .1) * 1000000000
      1100000000
    > (1 + .1) * 100000000000000
      110000000000000.02
    

    see? if you manage to see more digits, the anomalies (which inevitably are there) become visible too.

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

Sidebar

Related Questions

Most posts I have read regarding implementation of copy constructor is that you must
I have read most of the posts on here relating to this issue and
OK I have read many posts regarding Dual Licensing using MIT and GPL licenses.
I have read that most languages are becoming more and more like lisp, adopting
All - I have read several posts here about svn repositories layout best practices
I have read many fine algorithms for identifying the most significant bit for 32-
I have read various posts in stackoverflow and I am trying to figure out
I have read some of the questions and answers here, but it none match
I have read a lot of topic here and people tend to store IP
What is the main purpose of using CROSS APPLY ? I have read (vaguely,

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.