From a9e5fc8539a7796adb28c9da236df28aa1f38e21 Mon Sep 17 00:00:00 2001 From: erio Date: Wed, 1 Apr 2026 23:15:59 +0800 Subject: [PATCH] fix(ui): floating point precision in perTokenToMTok conversion --- frontend/src/components/admin/channel/types.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/admin/channel/types.ts b/frontend/src/components/admin/channel/types.ts index cea57da0..039e397d 100644 --- a/frontend/src/components/admin/channel/types.ts +++ b/frontend/src/components/admin/channel/types.ts @@ -42,7 +42,8 @@ export function mTokToPerToken(val: number | string | null | undefined): number /** 后端存储值(per-token) → 前端显示值($/MTok) */ export function perTokenToMTok(val: number | null | undefined): number | null { if (val === null || val === undefined) return null - return val * MTOK + // toPrecision(10) 消除 IEEE 754 浮点乘法精度误差,如 5e-8 * 1e6 = 0.04999...96 → 0.05 + return parseFloat((val * MTOK).toPrecision(10)) } export function apiIntervalsToForm(intervals: PricingInterval[]): IntervalFormEntry[] {