I have a basic program which I'm using to calculate the compound interest of a value, but when I return the value, it is correct but the program has added on more decimal places. Here's what the calculation look like if the principle (200) was increased by a rate (10%) for some time (3 years):
principle = float(input("Enter principle value: ")) #suppose you input 200
rate = float(input("Enter rate: ")) #suppose you input 30
time = float(input("Enter time: ")) # suppose you input 2
interest = (1+(rate/100))**time #This is the formula for calculating the interest
new_value = principle*interest
print (new_value)
This ends up printing: 266.2000000000001
, the answer is 266.2
which the program has calculated, but why is it adding the 000000000001
after the answer. I have tried f-string formatting
but that rounds the value to a decimal point. In this case, any other inputs would give different decimal points, and using f-string formatting
would prevent all the other values from being presented which one might require. How can I output/store the exact and correct value from these calculations, without it returning added binary values?