When I subtract 4.7 from 2.3, I get a number with 16 decimal places, instead of getting a specific number with one decimal place. How come it doesn't give you a specific answer?
Asked
Active
Viewed 56 times
-1
-
Additionally, please note that you should always use the generic [python] tag and include any version specific tags, optionally. – juanpa.arrivillaga Sep 06 '17 at 21:11
-
If you really need a precise value, Python has the `decimal` module. – wkl Sep 06 '17 at 21:13
1 Answers
2
This is because of the numerical representation of both decimal numbers (4.7
and 2.3
) in binary:
4.7 is represented in binary as 100.10110011001100110011...
2.3 is represented in binary as 10.01001100110011001101...
As you can see, both are periodic tithes in binary. This is why you do not obtain a precise result.
I hope it helps.

Community
- 1
- 1

Dalton Cézane
- 3,672
- 2
- 35
- 60