[issue24827] round(1.65, 1) return 1.6 with decimal

2017-07-31 Thread Mark Dickinson
Mark Dickinson added the comment: > I think it is better to make a tip in the Python tutorial. I'd recommend opening a separate issue (or pull request, if you're feeling adventurous) for that; this issue is old and closed, and it's unlikely many will be following it. -- _

[issue24827] round(1.65, 1) return 1.6 with decimal

2017-07-30 Thread Huan Wang
Huan Wang added the comment: Hi Mark, Thank you for your reply. I went over again the answer from Zachary Ware published on 2015-08-08 09:36. I got the point that it is better to use string type of number. >>> from decimal import Decimal, ROUND_HALF_UP >>> Decimal("1.45") Decimal('1.45') >>>

[issue24827] round(1.65, 1) return 1.6 with decimal

2017-07-30 Thread Mark Dickinson
Mark Dickinson added the comment: Huan, This isn't a bug: see the earlier comments from Zachary Ware on this issue for explanations. When you compute `rounded(1.45, 0.1)`, you convert the *float* 1.45 to a Decimal instance. Thanks to the What You See Is Not What You Get nature of binary float

[issue24827] round(1.65, 1) return 1.6 with decimal

2017-07-30 Thread Huan Wang
Huan Wang added the comment: Hello, I was confused by the decimal module. The problem is that I want to from decimal import Decimal, ROUND_HALF_UP def rounded(number, n): ''' Round the digits after the n_th decimal point by using decimal module in python. For example: 2.453

[issue24827] round(1.65, 1) return 1.6 with decimal

2015-08-08 Thread Zachary Ware
Zachary Ware added the comment: I'm glad you understand it now :) -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscr

[issue24827] round(1.65, 1) return 1.6 with decimal

2015-08-08 Thread umedoblock
umedoblock added the comment: excuse me. I understand ROUND_HALF_EVEN meaning. I think that __round__() function work ROUND_HALF_UP. so sorry. I don't have exactly knowledge about ROUND_HALF_EVEN. I misunderstand about ROUND_HALF_EVEN. I have thought ROUND_HALF_EVEN means ROUND_HALF_UP. SO SORRY

[issue24827] round(1.65, 1) return 1.6 with decimal

2015-08-08 Thread Merlijn van Deen
Merlijn van Deen added the comment: As Zachary explained, the behavior is correct. There are three issues in play here. 1) The rounding method. With the ROUND_HALF_EVEN rounding mode, .5 is rounded to the nearest *even* number, so 1.65 is rounded to 1.6, while 1.75 is rounded to 1.8. 2) Roun

[issue24827] round(1.65, 1) return 1.6 with decimal

2015-08-08 Thread umedoblock
umedoblock added the comment: I have a headache. because python reports many error after I patched below patches. --- Lib/test/test_decimal.py.orig 2015-08-08 17:41:01.986316738 +0900 +++ Lib/test/test_decimal.py2015-08-08 17:41:05.470316878 +0900 @@ -1935,6 +1935,7 @@ ('1

[issue24827] round(1.65, 1) return 1.6 with decimal

2015-08-08 Thread umedoblock
umedoblock added the comment: In this case. >>> round(1.65, 1) == 1.7 False >>> round(2.675, 2) == 2.68 False I never say anything. Because I understand what you said. But I use the decimal module. please pay attention to use decimal module. -- ___ P

[issue24827] round(1.65, 1) return 1.6 with decimal

2015-08-08 Thread umedoblock
umedoblock added the comment: In addition. >>> D(round(D("2.675"), 2)) == D("2.68") True >>> D(round(D("1.65"), 1)) == D("1.7") False I believe a bug or at least change the __round__(). -- ___ Python tracker _

[issue24827] round(1.65, 1) return 1.6 with decimal

2015-08-08 Thread umedoblock
umedoblock added the comment: last compared results are different. should be bug or at least think that how to get a same result about "D(round(df2, 2)) == D(round(ds2, 2))" >>> from decimal import Decimal as D >>> f1 = 1.65 >>> s1 = str(f1) >>> df1 = D(f1) >>> ds1 = D(s1) >>> f2 = 2.675 >>> s2

[issue24827] round(1.65, 1) return 1.6 with decimal

2015-08-07 Thread Zachary Ware
Zachary Ware added the comment: I think the key point that you're missing (and which I could have made clearer in my previous message) is that `Decimal(2.675) != Decimal('2.675')`. In the first case, a Decimal instance is created from a float, and 2.675 cannot be represented perfectly in base

[issue24827] round(1.65, 1) return 1.6 with decimal

2015-08-07 Thread Zachary Ware
Zachary Ware added the comment: The rounding mode of the default context is ROUND_HALF_EVEN[1]: >>> import decimal >>> decimal.getcontext() Context(prec=28, rounding=ROUND_HALF_EVEN, Emin=-99, Emax=99, capitals=1, clamp=0, flags=[], traps=[InvalidOperation, DivisionByZero, Overflow])

[issue24827] round(1.65, 1) return 1.6 with decimal

2015-08-07 Thread umedoblock
New submission from umedoblock: round(1.65, 1) return 1.6 with decimal. I feel bug adobe result. not bug ? >>> import decimal >>> d1 = decimal.Decimal("1.65") >>> d2 = decimal.Decimal(10 ** -2) * 5 >>> d1 Decimal('1.65') >>> d2 Decimal('0.05000104083408559') >>> d1 + d2 Decimal('1.70