>>> round(3.5) 4 >>> round(10.5) 10
Это так задумано или я что-то не понимаю?
Было убито не мало времени чтобы выяснить откуда косяки

>>> round(3.5) 4 >>> round(10.5) 10

Python 2.7.3 (default, Sep 26 2013, 20:03:06) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> round (3.5) 4.0 >>> round (10.5) 11.0 >>>
This is not a bug: it’s a result of the fact that most decimal fractions can’t be represented exactly as a float.и что получается товарищи, что Python3 не может осилить 10.5 как float? Пока мне кто то не разъяснит, выглядит это как дичайший бред.
smoke853Эээ, нет. В примечании написано про 2.675, а не про 10.5. Разница тут существенна, 10.5 в двоичной системе представляется как 1010.1, а 2.675 только как периодическая дробь 10.101(0110).
http://docs.python.org/3/library/functions.html?highlight=round#roundВ примечании про это написано.
>>> 10.49999999999999999999999999999999999999 10.5 >>> round(10.49999999999999999999999999999999999999) 10 >>> 10.49999999999999999999999999999999999999 == 10.5 True >>>
>>> round(10.5000000000000000000000001) 10 >>> round(10.500000000000001) 11 >>>
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import decimal >>> f=10.5 >>> d=decimal.Decimal(10.5) >>> map(round, (f,d)) [11.0, 11.0]
Python 3.3.0 (default, Oct 01 2012, 09:13:30) [GCC] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import decimal >>> d=decimal.Decimal(10.5) >>> f=10.5 >>> list(map(round, (f,d))) [10, 10]
>>> from decimal import Decimal >>> Decimal('10.5').quantize(Decimal('1.'), rounding='ROUND_HALF_UP') Decimal('11')