From 2d967f21ec87858b902d80907d153c4ea00e1a71 Mon Sep 17 00:00:00 2001 From: fish Date: Sat, 4 Jul 2026 11:06:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20change=5Fpct=20=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E6=8C=89=E5=B0=8F=E6=95=B0=E5=AD=98=E5=82=A8=E5=B9=B6=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E4=B9=98=E4=BB=A5100=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/internal/datasource/tickflow.go | 5 +++-- frontend/src/components/StockOverview.tsx | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/backend/internal/datasource/tickflow.go b/backend/internal/datasource/tickflow.go index 834b44d..d9c2ec7 100644 --- a/backend/internal/datasource/tickflow.go +++ b/backend/internal/datasource/tickflow.go @@ -38,13 +38,14 @@ type Quote struct { } `json:"ext"` } -// ChangePct 优先使用 ext.change_pct,否则根据 close/prev_close 计算。 +// ChangePct 优先使用 ext.change_pct(tickflow 返回小数,如 0.30 = 30%), +// 否则根据 close/prev_close 计算并统一返回小数形式。 func (q *Quote) ChangePct() float64 { if q.Ext.ChangePct != 0 { return q.Ext.ChangePct } if q.PrevClose != 0 { - return (q.Close - q.PrevClose) / q.PrevClose * 100 + return (q.Close - q.PrevClose) / q.PrevClose } return 0 } diff --git a/frontend/src/components/StockOverview.tsx b/frontend/src/components/StockOverview.tsx index c117146..b2c6561 100644 --- a/frontend/src/components/StockOverview.tsx +++ b/frontend/src/components/StockOverview.tsx @@ -133,7 +133,7 @@ export function StockOverview({ role }: StockOverviewProps) { } label="平均涨跌" - value={`${avg_change_pct >= 0 ? '+' : ''}${avg_change_pct.toFixed(2)}%`} + value={`${avg_change_pct >= 0 ? '+' : ''}${(avg_change_pct * 100).toFixed(2)}%`} valueClass={avg_change_pct >= 0 ? 'text-bull' : 'text-bear'} /> @@ -186,7 +186,7 @@ function IndexCard({ item }: { item: StockRow }) { {item.close.toFixed(2)}
- {positive ? '+' : ''}{item.change_pct.toFixed(2)}% + {positive ? '+' : ''}{(item.change_pct * 100).toFixed(2)}%
) @@ -209,7 +209,7 @@ function StockList({
暂无数据
) : ( rows.map((item, idx) => { - const val = valueKey === 'amount' ? (item.amount ?? 0) / 1e8 : item.change_pct + const val = valueKey === 'amount' ? (item.amount ?? 0) / 1e8 : item.change_pct * 100 const isPositive = valueKey === 'amount' ? true : item.change_pct >= 0 return (