Issue2179

classification
Title: Bug on multiplying
Type: behaviour Severity: major
Components: Core Versions: Jython 2.5
Milestone:
process
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: Nosy List: vborcea, zyasoft
Priority: Keywords:

Created on 2014-07-17.07:42:47 by vborcea, last changed 2014-07-17.16:12:09 by zyasoft.

Messages
msg8878 (view) Author: virgil (vborcea) Date: 2014-07-17.07:42:46
float(4.27*100) returns 426.99999999999994
Expected 427
msg8880 (view) Author: Jim Baker (zyasoft) Date: 2014-07-17.15:56:46
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')
msg8881 (view) Author: Jim Baker (zyasoft) Date: 2014-07-17.16:12:09
Decimal module docs go into this in greater detail - https://docs.python.org/2/library/decimal.html
History
Date User Action Args
2014-07-17 16:12:09zyasoftsetmessages: + msg8881
2014-07-17 15:57:00zyasoftsetstatus: open -> closed
resolution: invalid
2014-07-17 15:56:46zyasoftsetnosy: + zyasoft
messages: + msg8880
2014-07-17 07:42:47vborceacreate