I am writing a program that deals with adding floats to each other and found something weird.
Examples
---INPUT---
print(1+0.1)
print(1-0.1)
---OUTPUT---
1.10000000000001
0.99999999999999
Why is this happening and how do I stop it?
I am writing a program that deals with adding floats to each other and found something weird.
Examples
---INPUT---
print(1+0.1)
print(1-0.1)
---OUTPUT---
1.10000000000001
0.99999999999999
Why is this happening and how do I stop it?
To do this instead of using floats, I used a list where each value of the list represented by each part of the float that i need. This is not always the best soluton but for the wider application that I need it in this is the best solution!
e.g.
10 1 0.1 0.01
[5, 4, 0, 1]
=> 54.01