Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70281
| From | Robert Kern <robert.kern@gmail.com> |
|---|---|
| Subject | Re: Simple question |
| Date | 2014-04-15 19:30 +0100 |
| References | <534D7807.6050408@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9287.1397586654.18130.python-list@python.org> (permalink) |
On 2014-04-15 19:18, 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?
The `...` elides the exponent:
>>> 0.1 + 0.1 + 0.1 - 0.3
5.551115123125783e-17
If you copied that verbatim directly out of a book, that's just sloppy editing.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Simple question Robert Kern <robert.kern@gmail.com> - 2014-04-15 19:30 +0100
csiph-web