[issue21929] Rounding properly

2020-05-31 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Python 2.7 is no longer supported.

--
nosy: +serhiy.storchaka
resolution:  -> out of date
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



[issue21929] Rounding properly

2014-10-14 Thread Stefan Krah

Changes by Stefan Krah stefan-use...@bytereef.org:


--
nosy:  -skrah

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



[issue21929] Rounding properly

2014-09-08 Thread Robert

Robert added the comment:

I'm not sure if this is related or not, but on 3.4.1 I get the following: 

 print(round(float(3/2)))
2 (as expected)
 print(round(float(5/2)))
2 (expected 3, as float should round .5 up)

--
nosy: +fenofonts

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



[issue21929] Rounding properly

2014-09-08 Thread Geoffrey Spear

Geoffrey Spear added the comment:

Robert:

That is not related. Python 3's round() function, as documented, rounds halves 
to the even choice; what you describe is the expected behavior.

--
nosy: +geoffreyspear

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



[issue21929] Rounding properly

2014-07-07 Thread Jeroen de Jong

New submission from Jeroen de Jong:

I ma trying to find a way to round correctly. So far I get unexpected results 
for some values.

--
components: Windows
files: Rounding.py
messages: 222444
nosy: jeroen1225
priority: normal
severity: normal
status: open
title: Rounding properly
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file35880/Rounding.py

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



[issue21929] Rounding properly

2014-07-07 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
nosy: +mark.dickinson, skrah

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



[issue21929] Rounding properly

2014-07-07 Thread Mark Dickinson

Mark Dickinson added the comment:

This is working as designed, though admittedly the cause of the unexpected 
results is non-obvious.

In Python 2, there's no way to implement `round` for a general type:  instead, 
the `round` function converts its *input* to a Python (binary) float, and then 
rounds the resulting value.  So you're effectively doing:

 from decimal import Decimal
 round(float(Decimal('167.75')), 1)
167.8
 round(float(Decimal('167.85')), 1)
167.8
 round(float(Decimal('167.95')), 1)
167.9

And the results above are explainable in terms of rounding the corresponding 
floating-point value:  the closest exactly representable binary float to 167.85 
is 167.844315658113919198513031005859375, which is a touch less 
than the halfway mark, so rounds down.  Similarly, the closest exactly 
representable float to 167.95 is 
167.949998863131622783839702606201171875, which again rounds down.  
167.75 is already exactly representable as a float, so there you get the 
expected result.

In Python 3, `round` rounds the Decimal object directly without converting to 
float first, so you shouldn't see the above problems.  In Python 2, you'll need 
to stick to your quantize approach.

--

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



[issue21929] Rounding properly

2014-07-07 Thread Mark Dickinson

Mark Dickinson added the comment:

There may be an opportunity for a documentation improvement here: it would be 
helpful if the Python 2.7 documentation for the round function explained that 
its input is converted to float.

--
assignee:  - docs@python
components: +Documentation -Windows
nosy: +docs@python

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



[issue21929] Rounding properly

2014-07-07 Thread Raymond Hettinger

Raymond Hettinger added the comment:

FWIW, the FAQ in the decimal docs shows how to round Decimal objects using the 
quantize() method:  https://docs.python.org/2.7/library/decimal.html#decimal-faq

Unfortunately, only it Python 3 does the one-obvious-way-to-do-it work.

--
nosy: +rhettinger

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