changes 分母为0的情况

This commit is contained in:
P3ngSaM 2023-03-17 15:49:17 +08:00
parent 7e85f20d33
commit 5d23dff6af
1 changed files with 8 additions and 4 deletions

View File

@ -433,10 +433,14 @@ def func(schemas: ReportSchemas.SearchReportFlowReqBody, db: Session = Depends(g
year_list.append(year) year_list.append(year)
def calculate_change(current, last): def calculate_change(current, last):
current = float(current) try:
last = float(last) current = float(current)
change = current - last last = float(last)
trend = str(round((current - last) / last * 100, 2)).replace("-", "") change = current - last
trend = str(round((current - last) / last * 100, 2)).replace("-", "")
except ZeroDivisionError:
change = 0
trend = "0"
if change >= 0: if change >= 0:
res = '增长{}'.format(trend) res = '增长{}'.format(trend)
else: else: