In this program, I am asking the user to input two datetime, and I convert the differences between the two date times into several floats. difference_days is one of the float of total difference in days. so basically, I am writing this in for loop part of my code is below:
if difference_days.is_integer():
print(f'The difference is {int(difference_days)} days.')
else:
hours = (difference_days - int(difference_days))*24.0
print(int(difference_days))
print(difference_days)
print(difference_days - int(difference_days))
print(hours)
if difference_hours.is_integer():
print(f'The difference is {int(difference_days)} days and {int(hours)} hours.')
else:
... # other codes that handle minutes, seconds, microseconds
I did not post all the codes, because I think there's something wrong with the calculation in python. so those print statements between hours and the second if statement is just for test, and below is the output:
91
91.95833333333333
0.9583333333333286
22.999999999999886
I was confused why the third one starts to have more decimal places in the end while the second doesn't. How should I fix that? I would like it to only display the 12 decimals.