From 4d5dd30668c7c16537b9183422cbd69d996bc341 Mon Sep 17 00:00:00 2001 From: xiezhouwei Date: Tue, 23 Jun 2026 11:39:18 +0800 Subject: [PATCH] fix: prevent billing process total from rounding to 0 for very small amounts (e.g. low-ratio channel-only models) - Add formatBillingTotalDisplay: auto-scales from 2 to 6 decimal places when amount < 0.005 - Replace formatBillingDisplayPrice with formatBillingTotalDisplay in the billing total line - Prevents '= \' display when actual cost is a tiny positive value (e.g. 0.00002 USD) --- web/src/helpers/render.jsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/web/src/helpers/render.jsx b/web/src/helpers/render.jsx index 0457d0e..a304802 100644 --- a/web/src/helpers/render.jsx +++ b/web/src/helpers/render.jsx @@ -1503,6 +1503,19 @@ function formatBillingDisplayPrice(usdAmount, rate, digits = 2) { return parseFloat((usdAmount * rate).toFixed(digits)); } +/** + * 计费过程总额专用格式化:正常金额保持 2 位小数;极小金额(< 0.005)自动提升至 6 位小数, + * 避免因 toFixed(2) 归零导致「计费过程」显示为 0。 + */ +function formatBillingTotalDisplay(usdAmount, rate) { + const raw = usdAmount * rate; + if (raw <= 0) return 0; + const fixed2 = Number(raw.toFixed(2)); + if (fixed2 > 0) return fixed2; + const fixed6 = Number(raw.toFixed(6)); + return fixed6 > 0 ? fixed6 : 0; +} + function buildBillingText(key, vars) { return i18next.t(key, vars); } @@ -2529,7 +2542,7 @@ export function renderModelPrice( outputDesc, extraServices, symbol, - total: formatBillingDisplayPrice(price, rate), + total: formatBillingTotalDisplay(price, rate), }, ), ];