Итак, я работаю над этим небольшим калькулятором сложных процентов, и у меня возникла проблема, которую я не знаю, как исправить! По какой-то причине python, похоже, не заботится о том, что в числах есть десятичные дроби. Например, если в коде число 12588.01, оно трактуется как 12588. Любая помощь очень ценится!
p = 12588.01 #principle
r = 4.9 #rate as percent
t = 20 #time
# math
r = r / 100
# math and output
for i in range(t):
interest = p * r
#interest = round(interest, 2)
#generates the spaces between the time and numbers
timeSpace = 5 - len(str(i+1))
timeSpace = " " * int(timeSpace)
#generates the spaces used in the first part of the output
firstSpace = 10 - len(str(round(p)))
firstSpace = " " * int(firstSpace)
#generated the space used in the second part of the output
secondSpace = 10 - len(str(round(interest)))
secondSpace = " " * int(secondSpace)
#output
#print("Year: %d%s|%d%s|%d%s|%d" % (i+1, timeSpace, round(p, 2), firstSpace, interest, secondSpace, round(interest+p, 2)))
print("Year: %d%s|%d%s|%d%s|%d" % (i+1, timeSpace, float(p), firstSpace, float(interest), secondSpace, float(interest+p)))
p = p + interest
#p = round(p, 2)
Этот калькулятор работает с валютой и должен округляться из-за этого, однако во время моих попыток исправить код, я их закомментировал.