This is expected behavior for float:
$ jython27
Jython 2.7b3+ (default:2c45f75a5406, Jul 14 2014, 16:05:09)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_21
Type "help", "copyright", "credits" or "license" for more information.
>>> float(4.27*100)
426.99999999999994
$ python
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> float(4.27*100)
426.99999999999994
Use Decimal if you don't want to see this behavior, which is absolutely inherent to how (binary-based) floating point is implemented:
>>> from decimal import Decimal
>>> Decimal("4.27") * 100
Decimal('427.00')
|