Browse Source

🐛 fix(stock-data): 修复涨跌额和涨跌幅百分比计算错误

- 修正zd和pc变量赋值错误,交换两者计算逻辑
- pc变量现在正确表示涨跌额(item.c - prevItem.c)
- zd变量现在正确表示涨跌幅百分比((pc / prevItem.c) * 100)
yourname 6 months ago
parent
commit
931ed0f670
1 changed files with 2 additions and 2 deletions
  1. 2 2
      src/server/api/stock-data/history/[code]/get.ts

+ 2 - 2
src/server/api/stock-data/history/[code]/get.ts

@@ -152,8 +152,8 @@ const app = new OpenAPIHono<AuthContext>().openapi(routeDef, async (c) => {
       }
       }
       
       
       const prevItem = array[index - 1];
       const prevItem = array[index - 1];
-      const zd = item.c - prevItem.c;  // 涨跌幅百分比
-      // const pc = prevItem.c !== 0 ? (zd / prevItem.c) * 100 : 0;  // 涨跌额
+      const pc = item.c - prevItem.c;  // 涨跌额
+      const zd = prevItem.c !== 0 ? (pc / prevItem.c) * 100 : 0;  // 涨跌幅百分比
       const zf = prevItem.c !== 0 ? ((item.h - item.l) / prevItem.c) * 100 : 0;  // 振幅百分比
       const zf = prevItem.c !== 0 ? ((item.h - item.l) / prevItem.c) * 100 : 0;  // 振幅百分比
       
       
       return {
       return {