Python 3.8.1 Decimal error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: Code Review (https://python-forum.io/forum-46.html) +--- Thread: Python 3.8.1 Decimal error (/thread-24942.html) |
Python 3.8.1 Decimal error - christopherhornback - Mar-11-2020 So I was running a simple loop to get me a list of decimal places, and stumbled onto this. >>> for i,a in enumerate(list(range(20))): i, a*0.05 i, a*0.1 (0, 0.0) (0, 0.0) (1, 0.05) (1, 0.1) (2, 0.1) (2, 0.2) (3, 0.15000000000000002) (3, 0.30000000000000004) (4, 0.2) (4, 0.4) (5, 0.25) (5, 0.5) (6, 0.30000000000000004) (6, 0.6000000000000001) (7, 0.35000000000000003) (7, 0.7000000000000001) (8, 0.4) (8, 0.8) (9, 0.45) (9, 0.9) (10, 0.5) (10, 1.0) (11, 0.55) (11, 1.1) (12, 0.6000000000000001) (12, 1.2000000000000002) (13, 0.65) (13, 1.3) (14, 0.7000000000000001) (14, 1.4000000000000001) (15, 0.75) (15, 1.5) (16, 0.8) (16, 1.6) (17, 0.8500000000000001) (17, 1.7000000000000002) (18, 0.9) (18, 1.8) (19, 0.9500000000000001) (19, 1.9000000000000001) Obviously I could just use the round() function, but that defeats the purpose. I tried this in my normal script(with imported packages), in a fresh Idle(no imported packages), and a fresh shell. All have the same result. RE: Python 3.8.1 Decimal error - buran - Mar-11-2020 does this answer your question: https://docs.python.org/3.8/tutorial/floatingpoint.html |