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

问题描述 投票:0回答:2

所以我只是为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')

输出:

自Covid在加拿大首次死亡后70天82.92857142857143:加拿大每天的总死亡人数67.17142857142858:每天总的护理院死亡人数15.757142857142858:每天在疗养院外的总死亡人数

python decimal division equation
2个回答
0
投票

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


0
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.