[issue44034] Incorrect type casting of float into int

2021-05-04 Thread Tim Peters


Tim Peters  added the comment:

Please study the docs first:

https://docs.python.org/3/tutorial/floatingpoint.html

That will give you the background to understand why `int()` has nothing to do 
with this.

>>> 1.
2.0

That is, `int()` was passed 2.0 to begin with, because the binary float closest 
to the decimal value 1. is in fact 2.0.

If you can't live with that, use the `decimal` module instead:

>>> import decimal
>>> int(decimal.Decimal("1."))
1

--
nosy: +tim.peters
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44034] Incorrect type casting of float into int

2021-05-04 Thread Shreyan Avigyan


Change by Shreyan Avigyan :


--
versions: +Python 3.10, Python 3.11, Python 3.9 -Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44034] Incorrect type casting of float into int

2021-05-04 Thread Backbench Family


New submission from Backbench Family :

y = int(1.999) # fifteen decimal points
print(y)
1   # output is 1

y = int(1.) # sixteen decimal points
print(y)
2   # output is 2
It shows 1 when we type fifteen decimal whereas when we add sixteen decimal 
points the output becomes 2.

--
components: Windows
messages: 392919
nosy: hbutt4319, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: Incorrect type casting of float into int
type: compile error
versions: Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com