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)
|
||||
|
||||
def calculate_change(current, last):
|
||||
try:
|
||||
current = float(current)
|
||||
last = float(last)
|
||||
change = current - last
|
||||
trend = str(round((current - last) / last * 100, 2)).replace("-", "")
|
||||
except ZeroDivisionError:
|
||||
change = 0
|
||||
trend = "0"
|
||||
if change >= 0:
|
||||
res = '增长{}'.format(trend)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue