Python Forum
Python 3.8.1 Decimal error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python 3.8.1 Decimal error
#1
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.
Reply
#2
does this answer your question:
https://docs.python.org/3.8/tutorial/floatingpoint.html
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020