Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12814
| Date | 2011-09-06 00:00 -0700 |
|---|---|
| From | Gary Herron <gherron@islandtraining.com> |
| Subject | Re: Floating point multiplication in python |
| References | <3348A754-2874-4E18-9E90-F9DB131E6AA0@163.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.792.1315292754.27778.python-list@python.org> (permalink) |
On 09/05/2011 10:57 PM, xyz wrote:
> hi all:
>
> As we know , 1.1 * 1.1 is 1.21 .
> But in python ,I got following :
>
>>>> 1.1 * 1.1
> 1.2100000000000002
>
> why python get wrong result? Who can tell me where's the 0.0000000000000002 from?
It's not a python error It's the nature of floating point arithmetic
to be inaccurate on *ANY* computer. Python just allows you to see the
inaccuracies.
(But try:
print 1.1*1.1
and see that the print statement does hide the roundoff error from you.)
Read this for more info:
http://pyfaq.infogami.com/why-are-floating-point-calculations-so-inaccurate
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Floating point multiplication in python Gary Herron <gherron@islandtraining.com> - 2011-09-06 00:00 -0700 Re: Floating point multiplication in python Duncan Booth <duncan.booth@invalid.invalid> - 2011-09-06 08:30 +0000
csiph-web