Why does Python show `0.2 + 0.1` as `0.30000000000000004`? [duplicate]
问题 This question already has answers here : Can someone explain this: 0.2 + 0.1 = 0.30000000000000004? [duplicate] (2 answers) Closed 5 years ago . I have written the following code for generating a range with floats: def drange(start, stop, step): result = [] value = start while value <= stop: result.append(value) value += step return result When calling this function with this statement: print drange(0.1,1.0,0.1) I expected to obtain this: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0] But