Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.042 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; '0.1': 0.09; 'subject:question': 0.10; 'python': 0.11; '"..."': 0.16; "(i'm": 0.16; '0.3': 0.16; 'all.': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'pfxlen:0': 0.19; 'cc:addr:gmail.com': 0.22; 'to:name:python-list@python.org': 0.22; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; "i've": 0.25; '15,': 0.26; 'first,': 0.26; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'wondering': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; "skip:' 10": 0.31; 'closer': 0.31; 'url:python': 0.33; 'received:google.com': 0.35; 'really': 0.36; 'i.e.': 0.36; 'subject:Simple': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'read': 0.60; 'hope': 0.61; 'url:3': 0.61; 'first': 0.61; 'more': 0.64; 'close': 0.67; 'phil': 0.84; '1:18': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=WSg0uz+bvhwze4o/QNiI8S71wOcak1BBNX5UgG6vBOw=; b=WuNkfHfJ9pSfqwL+2l9sC88ly/jZLUHlEuusWiKa7su2829WGercJtlQzmEyROEt30 KCtgjEtYCPHAP6mIQMYlgd+EzPHobcskx0oIJtYyPPLLtaiGe4Tru9NT8CqVxnmsgg80 KbMyY8e32L2toDlVhHNvIOQi9ce6AXsY6sszWGTS/PaKErJ7PijOcNliwtCqLSWLzqhC +EoAgHGQS7/CmaamLPmotRuQs4MXQt0XK99+2/vLcItNKMgX6C8RE7uGO8nL4a2Mhhww WXWdg+Xy/+o6kon9cCWFHkJTavpd6+73gqO5z3wx2jOK2J2rxVy64Uh24M9ixQ1Df38G BUQQ== X-Received: by 10.60.54.228 with SMTP id m4mr2679195oep.29.1397586361535; Tue, 15 Apr 2014 11:26:01 -0700 (PDT) MIME-Version: 1.0 Sender: zachary.ware@gmail.com In-Reply-To: <534D7807.6050408@gmail.com> References: <534D7807.6050408@gmail.com> From: Zachary Ware Date: Tue, 15 Apr 2014 13:25:41 -0500 X-Google-Sender-Auth: -JmK18mQP-RDnOi4xw712tgUMKg Subject: Re: Simple question To: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1397586370 news.xs4all.nl 2840 [2001:888:2000:d::a6]:59984 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:70278 On Tue, Apr 15, 2014 at 1:18 PM, Phil Dobbin wrote: > Hi, all. > > I've just started to learn Python (I'm reading Mark Lutz's 'Learning > Python' from O'Reilly) & I'm confused as to this part: > > '>>> 0.1 + 0.1 + 0.1 - 0.3 > 5.55111.....' > > Using 'import Decimal' you can get a much closer result i.e. > 'Decimal('0.0')' > > What I'm wondering is why the first calculation that arrives at > '5.55111...' is so far out? First, note that the "..." part of "5.55111..." is very important here, it's actually "5.55111...e-17" which means it's really approximately 0.000000000000000055111, which is really very close to the answer you'd expect from a human. To learn more about why Python doesn't give 0.0, read this: https://docs.python.org/3/tutorial/floatingpoint.html Hope this helps, -- Zach