Message248260
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) Rounding of floats. Floats cannot represent every number, and numbers are therefore rounded.
- round(2.675, 2) = round(2.6749999999999998, 2) and is thus rounded to 2.67
- round(1.65, 1) = round(1.6499999999999999, 1) and is thus rounded to 1.6
3a) In Python 2, round returns a float, so Decimal(round(Decimal("1.65"))) = Decimal(1.6) = Decimal('1.600000000000000088817841970012523233890533447265625') != Decimal('1.6')
3b) In Python 3, Decimal.__round__ is implemented, so round(D("1.65"), 1) == D("1.6") as expected. |
|
Date |
User |
Action |
Args |
2015-08-08 10:52:29 | valhallasw | set | recipients:
+ valhallasw, umedoblock, zach.ware |
2015-08-08 10:52:29 | valhallasw | set | messageid: <1439031149.55.0.270447565265.issue24827@psf.upfronthosting.co.za> |
2015-08-08 10:52:29 | valhallasw | link | issue24827 messages |
2015-08-08 10:52:28 | valhallasw | create | |
|