changes 分母为0的情况
This commit is contained in:
parent
7e85f20d33
commit
5d23dff6af
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue