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

  • Home
  • SEARCH
  • 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 831157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:09:28+00:00 2026-05-15T04:09:28+00:00

i am kind of confused why python add some additional decimal number in this

  • 0

i am kind of confused why python add some additional decimal number in this case, please help to explain

>>> mylist = ["list item 1", 2, 3.14]
>>> print mylist ['list item 1', 2, 3.1400000000000001]
  • 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-15T04:09:29+00:00Added an answer on May 15, 2026 at 4:09 am

    Floating point numbers are an approximation, they cannot store decimal numbers exactly. Because they try to represent a very large range of numbers in only 64 bits, they must approximate to some extent.

    It is very important to be aware of this, because it results in some weird side-effects. For example, you might very reasonably think that the sum of ten lots of 0.1 would be 1.0. While this seems logical, it is also wrong when it comes to floating point:

    >>> f = 0.0
    >>> for _ in range (10):
    ...  f += 0.1
    ...
    >>> print f == 1.0
    False
    >>> f
    0.99999999999999989
    >>> str(f)
    1.0
    

    You might think that n / m * m == n. Once again, floating-point world disagrees:

    >>> (1.0 / 103.0) * 103.0
    0.99999999999999989
    

    Or perhaps just as strangely, one might think that for all n, n + 1 != n. In floating point land, numbers just don’t work like this:

    >>> 10.0**200
    9.9999999999999997e+199
    >>> 10.0**200 == 10.0**200 + 1
    True
    # How much do we have to add to 10.0**200 before its 
    # floating point representation changes?
    >>> 10.0**200 == 10.0**200 + 10.0**183
    True
    >>> 10.0**200 == 10.0**200 + 10.0**184
    False
    

    See What every computer scientist should know about floating point numbers for an excellent summary of the issues.

    If you need exact decimal representation, check out the decimal module, part of the python standard library since 2.4. It allows you to specify the number of significant figures. The downside is, it is much slower than floating point, because floating point operations are implemented in hardware whereas decimal operations happen purely in software. It also has its own imprecision issues, but if you need exact representation of decimal numbers (e.g. for a financial application) it’s ideal.

    For example:

    >>> 3.14
    3.1400000000000001
    >>> import decimal
    >>> decimal.Decimal('3.14')
    >>> print decimal.Decimal('3.14')
    3.14
    # change the precision:
    >>> decimal.getcontext().prec = 6
    >>> decimal.Decimal(1) / decimal.Decimal(7)
    Decimal('0.142857')
    >>> decimal.getcontext().prec = 28
    >>> decimal.Decimal(1) / decimal.Decimal(7)
    Decimal('0.1428571428571428571428571429')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.