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)
This commit is contained in:
parent
789f3b43e4
commit
4d5dd30668
|
|
@ -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),
|
||||
},
|
||||
),
|
||||
];
|
||||
|
|
|
|||
Loading…
Reference in New Issue