Why is there an error when splitting 2 / 5.0 in Python?

Possible duplicate:
Python float - str-float weirdness

In python 2/5.0or 2/float(5)returns0.40000000000000002

Why am I getting this error at the end and how can I get the correct value for use in advanced calculations?

+3
source share
5 answers

Welcome to IEEE754, enjoy your stay .

Use instead decimal.

+22
source

. ​​ , . , , .

+3

.

IEEE ​​ . , , .

. , . , - , , .

, , . Python - , , .

:

- "" . , , . .

-, , . , , ?

+2

, Python 3.1 , . . Python 3.1 ( " " ).

+2

See this question for an explanation. The right way is either

  • Use integers until final calculation
  • Live with rounding errors.
+1
source

Source: https://habr.com/ru/post/1732504/


All Articles