试图在输出中将除法方程的结果保留到小数点后两位?

Trying to get the results of division equation to two decimal places in out put?

所以我只是为加拿大的 Covid 死亡做了一个简单的文件,我似乎无法在除法后的输出中将小数位数减少到两位?

import datetime as dt
start_date = dt.date(2020, 3, 9)
end_date = dt.date(2020, 5, 18)
date_td = end_date - start_date

days_between = date_td.days
print(days_between, 'Days since first Covid death in Canada')
# March 3, 2020 was first recorded death in Canada.  70 days
total_deaths = 5805 / 70
print(total_deaths,':' 'Total Deaths in Canada per day')
carehome_deaths = 4702 / 70
print(carehome_deaths,':' 'Total Care Home deaths per day')

outside_deaths = 1103 / 70
print(outside_deaths,':' 'Total deaths outside of care homes per day')

输出:

距离加拿大首例新冠肺炎死亡已过去 70 天 82.92857142857143 :加拿大每天的总死亡人数 67.17142857142858 :护理院每天的总死亡人数 15.757142857142858 :每天护理院以外的总死亡人数

使用round(total_deaths, 2),希望对您有所帮助!

要在打印语句中四舍五入小数点,请执行以下操作:

print(round(total_deaths, 2), "....")

您可以在此处找到有关内置数据类型的更多信息round()