0

Something is happening and I have no idea why.

In python:

for j in range(1,10):
      print(0.1*j)

which returns:

0.1
0.2
0.30000000000000004
0.4
0.5
0.6000000000000001
0.7000000000000001
0.8
0.9

what is happening?

Euler_Salter
  • 3,271
  • 8
  • 33
  • 74
  • 1
    perhaps `0.1*integer` returns a float because `0.1` is a float? What were you expecting to happen? – John Coleman Jul 20 '17 at 15:37
  • My question is wrong ahaha but I mean why do I get 0.000001 ? – Euler_Salter Jul 20 '17 at 15:39
  • What is bugging you? According to the title of your question, you're expecting `0.1*int` to give you something else than a `float`, which is somewhat normal... – Right leg Jul 20 '17 at 15:39
  • See the linked-to question (the duplicated one: https://stackoverflow.com/q/588004/4996248). This is just standard floating point behavior since base 2 and base 10 don't really mesh well. – John Coleman Jul 20 '17 at 15:39
  • where is the linked question? – Euler_Salter Jul 20 '17 at 15:40
  • Consider reading into float data types. In the meantime if you want 3*.1 to give you 0.3 consider using a floor or round function. – brian Jul 20 '17 at 15:53

0 Answers0