From 5d23dff6af2b21aad030cca03bc5142c1840556a Mon Sep 17 00:00:00 2001 From: P3ngSaM <61768364+P3ngSaM@users.noreply.github.com> Date: Fri, 17 Mar 2023 15:49:17 +0800 Subject: [PATCH] =?UTF-8?q?changes=20=E5=88=86=E6=AF=8D=E4=B8=BA0=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Router/ReportRouter.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/App/Router/ReportRouter.py b/App/Router/ReportRouter.py index a5a1700..c3febb7 100644 --- a/App/Router/ReportRouter.py +++ b/App/Router/ReportRouter.py @@ -433,10 +433,14 @@ def func(schemas: ReportSchemas.SearchReportFlowReqBody, db: Session = Depends(g year_list.append(year) def calculate_change(current, last): - current = float(current) - last = float(last) - change = current - last - trend = str(round((current - last) / last * 100, 2)).replace("-", "") + 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: