int vs. float

Dan Sommers dan at tombstonezero.net
Fri Feb 10 21:17:26 EST 2017


On Fri, 10 Feb 2017 20:46:16 +0000, Erik wrote:

> Python 3.5.2 (default, Nov 17 2016, 17:05:23)
> [GCC 5.4.0 20160609] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> 0.99999999999999995
> 1.0
>  >>> f = float("0.99999999999999995")
>  >>> i = int(f)
>  >>> i
> 1
>  >>> f
> 1.0
>  >>> i == f
> True
>  >>>
> 
> E.

At least it works both ways:

Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> s = "33333333333333333333333333333333333333333333333333333333333333333"
>>> f = float(s)
>>> i = int(s)
>>> i
33333333333333333333333333333333333333333333333333333333333333333
>>> f
3.3333333333333333e+64
>>> i == f
False



More information about the Python-list mailing list