diff --git a/sidecars/panel/app.js b/sidecars/panel/app.js index 1b1b294..b632dd6 100644 --- a/sidecars/panel/app.js +++ b/sidecars/panel/app.js @@ -4014,7 +4014,7 @@ return { defineComponent }; })(); // --- src/core/formatters.js --- -const { formatMetric, formatSpeedMetric, formatCachePct, getSpeedToneClass, getCacheToneClass, getStepCostToneClass, getTtftToneClass, formatTokens, formatTokensPrecise, formatCnyApprox, formatDateSpanBadge, formatUsd, speedReasonText, formatAnomalyKindLabel, formatAnomalyTagText, resolveModelAnomalySummary, formatStepAnomalyInlineSummary, buildStepAnomalyDiagnostic, buildStepCompactionDiagnostic, formatTimingDetailSec, hasStepTimingData, buildStepTimingDiagnostic, buildModelAnomalyDiagnostic, sampleSummary, formatCountdown, formatCompactDateTime, formatElapsedSec, stripVendorModelPrefix, normalizeOrchestratorIdDisplayMode, resolveModelDisplayInfo, mergeModelsByDisplayName, getAgentBadgeClass, formatAgentBadgeText, formatAgentLabel, formatConversationMeta, formatLiveActivityLabel, formatLiveActivityDetail, getCanonicalModelColorSeed, resolveDeterministicModelColor, buildDeterministicModelColorMap } = (() => { +const { formatMetric, formatSpeedMetric, formatCachePct, formatPctNumber, getSpeedToneClass, getCacheToneClass, getStepCostToneClass, getTtftToneClass, formatTokens, formatTokensPrecise, formatCnyApprox, formatDateSpanBadge, formatUsd, speedReasonText, formatAnomalyKindLabel, formatAnomalyTagText, resolveModelAnomalySummary, formatStepAnomalyInlineSummary, buildStepAnomalyDiagnostic, buildStepCompactionDiagnostic, formatTimingDetailSec, hasStepTimingData, buildStepTimingDiagnostic, buildModelAnomalyDiagnostic, sampleSummary, formatCountdown, formatCompactDateTime, formatElapsedSec, stripVendorModelPrefix, normalizeOrchestratorIdDisplayMode, resolveModelDisplayInfo, mergeModelsByDisplayName, getAgentBadgeClass, formatAgentBadgeText, formatAgentLabel, formatConversationMeta, formatLiveActivityLabel, formatLiveActivityDetail, getCanonicalModelColorSeed, resolveDeterministicModelColor, buildDeterministicModelColorMap } = (() => { /** * @fileoverview Pure formatting utilities for speed metrics, token counts, * USD estimates, countdown timers, and custom datetime displays. @@ -4042,6 +4042,26 @@ function formatCachePct(value) { return `${num}%`; } +/** + * 格式化百分比数值文本:常规值保留 1 位小数,将边界值 `0.0` / `100.0` 收口为整数 `0` / `100`。 + * + * @param {number|string|null|undefined} value + * @param {{ withSymbol?: boolean }} [options] + * @returns {string} + */ +function formatPctNumber(value, { withSymbol = false } = {}) { + const num = Number(value); + if (!Number.isFinite(num)) return withSymbol ? '0%' : '0'; + const rounded = Math.round(num * 10) / 10; + const str = + Math.abs(rounded) < 1e-9 + ? '0' + : Math.abs(rounded - 100) < 1e-9 + ? '100' + : rounded.toFixed(1); + return withSymbol ? `${str}%` : str; +} + function getSpeedToneClass(tokPerSec) { return `tone-${classifySpeedTier(tokPerSec)}`; } @@ -5319,7 +5339,7 @@ function buildDeterministicModelColorMap(models = []) { return colorMap; } -return { formatMetric, formatSpeedMetric, formatCachePct, getSpeedToneClass, getCacheToneClass, getStepCostToneClass, getTtftToneClass, formatTokens, formatTokensPrecise, formatCnyApprox, formatDateSpanBadge, formatUsd, speedReasonText, formatAnomalyKindLabel, formatAnomalyTagText, resolveModelAnomalySummary, formatStepAnomalyInlineSummary, buildStepAnomalyDiagnostic, buildStepCompactionDiagnostic, formatTimingDetailSec, hasStepTimingData, buildStepTimingDiagnostic, buildModelAnomalyDiagnostic, sampleSummary, formatCountdown, formatCompactDateTime, formatElapsedSec, stripVendorModelPrefix, normalizeOrchestratorIdDisplayMode, resolveModelDisplayInfo, mergeModelsByDisplayName, getAgentBadgeClass, formatAgentBadgeText, formatAgentLabel, formatConversationMeta, formatLiveActivityLabel, formatLiveActivityDetail, getCanonicalModelColorSeed, resolveDeterministicModelColor, buildDeterministicModelColorMap }; +return { formatMetric, formatSpeedMetric, formatCachePct, formatPctNumber, getSpeedToneClass, getCacheToneClass, getStepCostToneClass, getTtftToneClass, formatTokens, formatTokensPrecise, formatCnyApprox, formatDateSpanBadge, formatUsd, speedReasonText, formatAnomalyKindLabel, formatAnomalyTagText, resolveModelAnomalySummary, formatStepAnomalyInlineSummary, buildStepAnomalyDiagnostic, buildStepCompactionDiagnostic, formatTimingDetailSec, hasStepTimingData, buildStepTimingDiagnostic, buildModelAnomalyDiagnostic, sampleSummary, formatCountdown, formatCompactDateTime, formatElapsedSec, stripVendorModelPrefix, normalizeOrchestratorIdDisplayMode, resolveModelDisplayInfo, mergeModelsByDisplayName, getAgentBadgeClass, formatAgentBadgeText, formatAgentLabel, formatConversationMeta, formatLiveActivityLabel, formatLiveActivityDetail, getCanonicalModelColorSeed, resolveDeterministicModelColor, buildDeterministicModelColorMap }; })(); // --- src/core/stepInspector.js --- @@ -5581,10 +5601,12 @@ function buildStepDiagnosticMarkdown( const promptTok = Number(st.inputTokens || 0) + Number(st.cacheReadTokens || 0); const cachePct = st.cacheHitPct != null && Number.isFinite(Number(st.cacheHitPct)) - ? `${Number(st.cacheHitPct).toFixed(1)}%` + ? formatPctNumber(st.cacheHitPct, { withSymbol: true }) : promptTok > 0 - ? `${((Number(st.cacheReadTokens || 0) / promptTok) * 100).toFixed(1)}%` - : '0.0%'; + ? formatPctNumber((Number(st.cacheReadTokens || 0) / promptTok) * 100, { + withSymbol: true, + }) + : '0%'; const ctxTok = Number(st.contextTokens || promptTok + Number(st.outputTokens || 0)); const ctxDelta = prevContextTokens != null && ctxTok > 0 @@ -6962,10 +6984,10 @@ function buildStepsCsv(steps, { displaySettings = {}, includeBom = true } = {}) const promptTok = inTok + cacheTok; const cachePct = st.cacheHitPct != null && Number.isFinite(Number(st.cacheHitPct)) - ? Number(st.cacheHitPct).toFixed(1) + ? formatPctNumber(st.cacheHitPct) : promptTok > 0 - ? ((cacheTok / promptTok) * 100).toFixed(1) - : '0.0'; + ? formatPctNumber((cacheTok / promptTok) * 100) + : '0'; const ctxTok = Number(st.contextTokens || promptTok + outTok); const anomCount = Number(st.anomaly?.count || 0); const anomDesc = @@ -7226,7 +7248,7 @@ function buildStepsMarkdownReport( const agg = summarizeStepsForExport(list, displaySettings); const totalTok = agg.sumIn + agg.sumCache + agg.sumOut; - const cacheHitPct = (computeCacheHitRatio(agg.sumIn, agg.sumCache) * 100).toFixed(1); + const cacheHitPct = formatPctNumber(computeCacheHitRatio(agg.sumIn, agg.sumCache) * 100); const avgTps = agg.tpsCnt > 0 ? formatSpeedMetric(agg.tpsSum / agg.tpsCnt, ' tok/s') : '—'; const avgTtft = agg.ttftCnt > 0 ? formatMetric(agg.ttftSum / agg.ttftCnt, 's') : '—'; const heading = title @@ -7267,7 +7289,9 @@ function buildStepsMarkdownReport( ); for (const m of agg.sortedModels) { const mTotal = m.inTok + m.cacheTok + m.outTok; - const mCache = `${(computeCacheHitRatio(m.inTok, m.cacheTok) * 100).toFixed(1)}%`; + const mCache = formatPctNumber(computeCacheHitRatio(m.inTok, m.cacheTok) * 100, { + withSymbol: true, + }); const mTps = m.tpsCnt > 0 ? formatSpeedMetric(m.tpsSum / m.tpsCnt, ' tok/s') : '—'; lines.push( `| ${escapeMdCell(m.label)} | ${m.calls} | ${formatTokensPrecise(mTotal)} | ${mCache} | ${mTps} | ${formatUsd(m.cost, { precise: m.cost > 0 && m.cost < 0.1 })} |` @@ -7368,7 +7392,7 @@ function buildConsumptionCsv( Number(acc.cacheReadTokens || 0), Number(acc.outputTokens || 0), Number(acc.totalTokens || 0), - Number(acc.cacheHitPct || 0).toFixed(1), + formatPctNumber(acc.cacheHitPct || 0), Number(acc.costUsd || 0).toFixed(4), `saved_usd=${Number(acc.savedCostUsd || 0).toFixed(4)}`, ]), @@ -7384,7 +7408,7 @@ function buildConsumptionCsv( Number(m.cacheReadTokens || 0), Number(m.outputTokens || 0), Number(m.totalTokens || 0), - Number(m.cacheHitPct || 0).toFixed(1), + formatPctNumber(m.cacheHitPct || 0), Number(m.costUsd || 0).toFixed(4), m.avgTokPerSec != null ? `avg_tps=${Number(m.avgTokPerSec).toFixed(1)}` : '', ]) @@ -7401,7 +7425,7 @@ function buildConsumptionCsv( Number(w.cacheReadTokens || 0), Number(w.responseTokens || 0) + Number(w.thinkingTokens || 0), Number(w.totalTokens || 0), - Number(w.cacheHitPct || 0).toFixed(1), + formatPctNumber(w.cacheHitPct || 0), Number(w.costUsd || 0).toFixed(4), `sessions=${Number(w.sessionCount || 0)}`, ]) @@ -7418,7 +7442,7 @@ function buildConsumptionCsv( Number(c.cacheReadTokens || 0), Number(c.responseTokens || 0) + Number(c.thinkingTokens || 0), Number(c.totalTokens || 0), - Number(c.cacheHitPct || 0).toFixed(1), + formatPctNumber(c.cacheHitPct || 0), Number(c.costUsd || 0).toFixed(4), c.sourceName || c.appSource || '', ]) @@ -7966,14 +7990,14 @@ function buildConsumptionMarkdownReport( '', `- **Total Tokens**: ${formatTokensPrecise(acc.totalTokens || 0)} (${Number(acc.calls || 0)} calls)`, `- **Est. Cost**: ${formatUsd(acc.costUsd || 0)} (Cache Saved ${formatUsd(acc.savedCostUsd || 0)})`, - `- **Cache Hit Rate**: ${Number(acc.cacheHitPct || 0).toFixed(1)}% (Input ${formatTokensPrecise(acc.inputTokens || 0)} / Cache ${formatTokensPrecise(acc.cacheReadTokens || 0)} / Output ${formatTokensPrecise(acc.outputTokens || 0)})`, + `- **Cache Hit Rate**: ${formatPctNumber(acc.cacheHitPct || 0, { withSymbol: true })} (Input ${formatTokensPrecise(acc.inputTokens || 0)} / Cache ${formatTokensPrecise(acc.cacheReadTokens || 0)} / Output ${formatTokensPrecise(acc.outputTokens || 0)})`, ] : [ `# 用量统计报告 · ${rangeLabel}`, '', `- **总 Token**: ${formatTokensPrecise(acc.totalTokens || 0)}(共 ${Number(acc.calls || 0)} 次调用)`, `- **预估费用**: ${formatUsd(acc.costUsd || 0)}(缓存节省 ${formatUsd(acc.savedCostUsd || 0)})`, - `- **缓存命中率**: ${Number(acc.cacheHitPct || 0).toFixed(1)}%(新输入 ${formatTokensPrecise(acc.inputTokens || 0)} / 缓存读取 ${formatTokensPrecise(acc.cacheReadTokens || 0)} / 输出 ${formatTokensPrecise(acc.outputTokens || 0)})`, + `- **缓存命中率**: ${formatPctNumber(acc.cacheHitPct || 0, { withSymbol: true })}(新输入 ${formatTokensPrecise(acc.inputTokens || 0)} / 缓存读取 ${formatTokensPrecise(acc.cacheReadTokens || 0)} / 输出 ${formatTokensPrecise(acc.outputTokens || 0)})`, ]; if (models.length > 0) { @@ -7988,7 +8012,7 @@ function buildConsumptionMarkdownReport( ); for (const m of models) { lines.push( - `| ${escapeMdCell(m.displayText || m.label || m.shortName)} | ${Number(m.calls || 0)} | ${formatTokensPrecise(m.totalTokens || 0)} | ${Number(m.cacheHitPct || 0).toFixed(1)}% | ${m.avgTokPerSec != null ? formatSpeedMetric(m.avgTokPerSec, ' tok/s') : '—'} | ${formatUsd(m.costUsd || 0)} |` + `| ${escapeMdCell(m.displayText || m.label || m.shortName)} | ${Number(m.calls || 0)} | ${formatTokensPrecise(m.totalTokens || 0)} | ${formatPctNumber(m.cacheHitPct || 0, { withSymbol: true })} | ${m.avgTokPerSec != null ? formatSpeedMetric(m.avgTokPerSec, ' tok/s') : '—'} | ${formatUsd(m.costUsd || 0)} |` ); } } @@ -8005,7 +8029,7 @@ function buildConsumptionMarkdownReport( ); for (const w of workspaces) { lines.push( - `| ${escapeMdCell(w.label || w.workspacePath || (en ? 'Unbound' : '未绑定工作区'))} | ${Number(w.sessionCount || 0)} | ${Number(w.calls || 0)} | ${formatTokensPrecise(w.totalTokens || 0)} | ${Number(w.cacheHitPct || 0).toFixed(1)}% | ${formatUsd(w.costUsd || 0)} |` + `| ${escapeMdCell(w.label || w.workspacePath || (en ? 'Unbound' : '未绑定工作区'))} | ${Number(w.sessionCount || 0)} | ${Number(w.calls || 0)} | ${formatTokensPrecise(w.totalTokens || 0)} | ${formatPctNumber(w.cacheHitPct || 0, { withSymbol: true })} | ${formatUsd(w.costUsd || 0)} |` ); } } @@ -8022,7 +8046,7 @@ function buildConsumptionMarkdownReport( ); for (const c of sessions.slice(0, 8)) { lines.push( - `| ${escapeMdCell(c.title || c.cascadeId)} | ${Number(c.calls || 0)} | ${formatTokensPrecise(c.totalTokens || 0)} | ${Number(c.cacheHitPct || 0).toFixed(1)}% | ${formatUsd(c.costUsd || 0)} |` + `| ${escapeMdCell(c.title || c.cascadeId)} | ${Number(c.calls || 0)} | ${formatTokensPrecise(c.totalTokens || 0)} | ${formatPctNumber(c.cacheHitPct || 0, { withSymbol: true })} | ${formatUsd(c.costUsd || 0)} |` ); } } @@ -12815,7 +12839,7 @@ const ContextSegmentMeter = defineComponent({ slotEl, 'title', isActive - ? `${t(item.def.labelKey)} · ${formatTokens(item.val)} (${item.pct.toFixed(1)}%)` + ? `${t(item.def.labelKey)} · ${formatTokens(item.val)} (${formatPctNumber(item.pct, { withSymbol: true })})` : null ); } @@ -14856,7 +14880,7 @@ function formatYAxisTick(metric, val, step) { return step >= 1 ? `${Math.round(val)}s` : `${val.toFixed(1)}s`; } if (metric === 'cache') { - return step >= 1 ? `${Math.round(val)}%` : `${val.toFixed(1)}%`; + return step >= 1 ? `${Math.round(val)}%` : formatPctNumber(val, { withSymbol: true }); } if (metric === 'cost') { if (step >= 1) return `$${Math.round(val)}`; @@ -14931,7 +14955,7 @@ function formatChartMetricValue(metric, val) { case 'ttft': return formatMetric(val, 's'); case 'cache': - return `${val.toFixed(1)}%`; + return formatPctNumber(val, { withSymbol: true }); case 'cost': return formatUsd(val, { precise: true }); default: @@ -14950,7 +14974,7 @@ function formatChartMetricCompact(metric, val) { case 'ttft': return formatMetric(val, 's'); case 'cache': - return `${val.toFixed(1)}%`; + return formatPctNumber(val, { withSymbol: true }); case 'cost': return formatUsd(val, { precise: true }); default: @@ -18345,8 +18369,8 @@ function syncQuotaWindowMeter({ const resetStr = hasData ? formatCountdown(resetTime) : ''; if (hasData && rsvVal > 0) { - const rsvStr = rsvVal.toFixed(1); - const actualStr = actualVal.toFixed(1); + const rsvStr = formatPctNumber(rsvVal); + const actualStr = formatPctNumber(actualVal); const leases = Math.max(1, Number(leaseCount) || 1); const tipText = leases >= 2 @@ -18354,13 +18378,13 @@ function syncQuotaWindowMeter({ : t('quota.reservedTip', { rsv: rsvStr, actual: actualStr }); patchText( metaBeforeEl, - t('quota.usedBeforeReserved', { reset: resetStr, used: usedVal.toFixed(1) }) + t('quota.usedBeforeReserved', { reset: resetStr, used: formatPctNumber(usedVal) }) ); metaReservedEl.hidden = false; patchText(metaReservedEl, t('quota.reservedTag', { rsv: rsvStr })); patchAttr(metaReservedEl, 'title', tipText); metaAfterEl.hidden = false; - patchText(metaAfterEl, t('quota.usedAfterReserved', { rem: remVal.toFixed(1) })); + patchText(metaAfterEl, t('quota.usedAfterReserved', { rem: formatPctNumber(remVal) })); patchAttr(trackEl, 'title', tipText); const actualWidth = +Math.min(100, actualVal).toFixed(2); const rsvWidth = +Math.min(Math.max(0, 100 - actualWidth), rsvVal).toFixed(2); @@ -18373,8 +18397,8 @@ function syncQuotaWindowMeter({ hasData ? t('quota.usedAndLeft', { reset: resetStr, - used: usedVal.toFixed(1), - rem: remVal.toFixed(1), + used: formatPctNumber(usedVal), + rem: formatPctNumber(remVal), }) : fallbackMetaText ); @@ -29340,7 +29364,7 @@ const ConsumptionView = defineComponent({ responseTokens, outputTokens: responseTokens + thinkingTokens, tokText: formatTokensPrecise(tok), - pctText: `${pct.toFixed(1)}%`, + pctText: formatPctNumber(pct, { withSymbol: true }), color, isOther: false, }; @@ -29377,7 +29401,7 @@ const ConsumptionView = defineComponent({ responseTokens: otherResp, outputTokens: otherResp + otherThink, tokText: formatTokensPrecise(otherTok), - pctText: `${otherPct.toFixed(1)}%`, + pctText: formatPctNumber(otherPct, { withSymbol: true }), color: 'var(--cons-other-seg)', isOther: true, }); @@ -29541,7 +29565,7 @@ const ConsumptionView = defineComponent({ : promptTok > 0 && Number(item.cacheReadTokens || 0) > 0 ? +((Number(item.cacheReadTokens || 0) / promptTok) * 100).toFixed(1) : 0; - const cachePctStr = cachePctVal.toFixed(1); + const cachePctStr = formatPctNumber(cachePctVal); const effCostPer1M = !isAllUnpriced && costVal > 0 && total >= 1000 ? costVal / (total / 1_000_000) : null; const outTok = Number( @@ -29555,7 +29579,7 @@ const ConsumptionView = defineComponent({ const barPct = costBase > 0 && costVal > 0 ? Math.min(100, Math.max(1, (costVal / costBase) * 100)) : 0; patchAttr(refs.pctBadge, 'hidden', false); patchAttr(refs.pctBadge, 'title', null); - patchText(refs.pctBadge, `${costShare.toFixed(1)}%`); + patchText(refs.pctBadge, formatPctNumber(costShare, { withSymbol: true })); patchText(refs.totalTokEl, isAllUnpriced ? '' : formatCnyApprox(costVal)); patchText(refs.costEl, costText); @@ -29630,7 +29654,7 @@ const ConsumptionView = defineComponent({ callsBase > 0 && callsCount > 0 ? Math.min(100, Math.max(1, (callsCount / callsBase) * 100)) : 0; patchAttr(refs.pctBadge, 'hidden', false); patchAttr(refs.pctBadge, 'title', null); - patchText(refs.pctBadge, `${callsShare.toFixed(1)}%`); + patchText(refs.pctBadge, formatPctNumber(callsShare, { withSymbol: true })); patchText(refs.totalTokEl, formatTokensPrecise(total)); patchText(refs.costEl, t('cons.callsCount', { calls: callsCount })); @@ -29670,7 +29694,7 @@ const ConsumptionView = defineComponent({ grandTotalTokens > 0 && total > 0 ? Math.min(1, Math.max(0.008, total / grandTotalTokens)) : 0; patchAttr(refs.pctBadge, 'hidden', false); patchAttr(refs.pctBadge, 'title', null); - patchText(refs.pctBadge, `${share.toFixed(1)}%`); + patchText(refs.pctBadge, formatPctNumber(share, { withSymbol: true })); patchText(refs.totalTokEl, formatTokensPrecise(total)); patchText(refs.costEl, costText); @@ -29844,7 +29868,7 @@ const ConsumptionView = defineComponent({ const share = grandTotalTokens > 0 ? +((total / grandTotalTokens) * 100).toFixed(1) : 0; const scaleRatio = grandTotalTokens > 0 && total > 0 ? Math.min(1, Math.max(0.01, total / grandTotalTokens)) : 0; - patchText(refs.pctBadge, `${share.toFixed(1)}%`); + patchText(refs.pctBadge, formatPctNumber(share, { withSymbol: true })); patchText(refs.totalTokEl, formatTokensPrecise(total)); const costVal = Number(item.costUsd || 0); @@ -30095,7 +30119,7 @@ const ConsumptionView = defineComponent({ ? Math.min(1, Math.max(0.01, total / tokBase)) : 0; - patchText(refs.pctBadge, `${share.toFixed(1)}%`); + patchText(refs.pctBadge, formatPctNumber(share, { withSymbol: true })); if (sortMode === 'tokens') { patchText(refs.totalTokEl, costText); patchText(refs.costEl, formatTokensPrecise(total)); @@ -30165,7 +30189,7 @@ const ConsumptionView = defineComponent({ if (showFallbackMeta) { const srcLabel = item.sourceName || item.appSource || ''; const cacheLabel = t('cons.topConvCacheMeta', { - pct: Number(item.cacheHitPct ?? 0).toFixed(1), + pct: formatPctNumber(item.cacheHitPct ?? 0), }); patchText(refs.fallbackMetaEl, srcLabel ? `${srcLabel} · ${cacheLabel}` : cacheLabel); } @@ -30282,7 +30306,7 @@ const ConsumptionView = defineComponent({ patchText(heroCostUsd, formatUsd(costUsd)); patchText(heroCostCny, formatCnyApprox(costUsd)); - patchText(cacheHitPctEl, `${Number(acct.cacheHitPct ?? 0).toFixed(1)}%`); + patchText(cacheHitPctEl, formatPctNumber(acct.cacheHitPct ?? 0, { withSymbol: true })); patchText(cacheTokensEl, t('cons.cacheHitTokens', { tokens: formatTokensPrecise(cacheTokens) })); let inPct = 0; @@ -31533,7 +31557,7 @@ const StepsDetailView = defineComponent({ patchText(inspKpiCache.lbl, t('steps.inspCacheLabel')); patchText(inspKpiCache.val, formatTokensPrecise(cacheTok)); - patchText(inspKpiCache.sub, `${cachePct.toFixed(1)}%`); + patchText(inspKpiCache.sub, formatPctNumber(cachePct, { withSymbol: true })); patchText(inspKpiOutput.lbl, t('steps.inspOutputLabel')); patchText(inspKpiOutput.val, formatTokensPrecise(outTok)); diff --git a/sidecars/panel/index.html b/sidecars/panel/index.html index cea9490..1c3b438 100644 --- a/sidecars/panel/index.html +++ b/sidecars/panel/index.html @@ -4,11 +4,11 @@ 用量监控 - +
- + diff --git a/sidecars/panel/src/components/charts/SessionStepCharts.js b/sidecars/panel/src/components/charts/SessionStepCharts.js index 1af6fa6..b754b92 100644 --- a/sidecars/panel/src/components/charts/SessionStepCharts.js +++ b/sidecars/panel/src/components/charts/SessionStepCharts.js @@ -12,6 +12,7 @@ import { h, patchAttr, patchClasses, patchStyleVar, patchText } from '../../core import { formatAgentBadgeText, formatMetric, + formatPctNumber, formatSpeedMetric, formatStepAnomalyInlineSummary, formatTokens, @@ -573,7 +574,7 @@ function formatYAxisTick(metric, val, step) { return step >= 1 ? `${Math.round(val)}s` : `${val.toFixed(1)}s`; } if (metric === 'cache') { - return step >= 1 ? `${Math.round(val)}%` : `${val.toFixed(1)}%`; + return step >= 1 ? `${Math.round(val)}%` : formatPctNumber(val, { withSymbol: true }); } if (metric === 'cost') { if (step >= 1) return `$${Math.round(val)}`; @@ -648,7 +649,7 @@ function formatChartMetricValue(metric, val) { case 'ttft': return formatMetric(val, 's'); case 'cache': - return `${val.toFixed(1)}%`; + return formatPctNumber(val, { withSymbol: true }); case 'cost': return formatUsd(val, { precise: true }); default: @@ -667,7 +668,7 @@ function formatChartMetricCompact(metric, val) { case 'ttft': return formatMetric(val, 's'); case 'cache': - return `${val.toFixed(1)}%`; + return formatPctNumber(val, { withSymbol: true }); case 'cost': return formatUsd(val, { precise: true }); default: diff --git a/sidecars/panel/src/components/ui/ContextSegmentMeter.js b/sidecars/panel/src/components/ui/ContextSegmentMeter.js index b342f43..1d002e5 100644 --- a/sidecars/panel/src/components/ui/ContextSegmentMeter.js +++ b/sidecars/panel/src/components/ui/ContextSegmentMeter.js @@ -6,7 +6,7 @@ import { defineComponent } from '../../core/component.js'; import { h, patchAttr, patchClasses, patchStyleVar } from '../../core/domPatch.js'; -import { formatTokens } from '../../core/formatters.js'; +import { formatPctNumber, formatTokens } from '../../core/formatters.js'; import { t } from '../../i18n/index.js'; const SEGMENT_DEFS = [ @@ -84,7 +84,7 @@ export const ContextSegmentMeter = defineComponent({ slotEl, 'title', isActive - ? `${t(item.def.labelKey)} · ${formatTokens(item.val)} (${item.pct.toFixed(1)}%)` + ? `${t(item.def.labelKey)} · ${formatTokens(item.val)} (${formatPctNumber(item.pct, { withSymbol: true })})` : null ); } diff --git a/sidecars/panel/src/components/widgets/QuotaPoolsWidget.js b/sidecars/panel/src/components/widgets/QuotaPoolsWidget.js index d9312e3..b3f2532 100644 --- a/sidecars/panel/src/components/widgets/QuotaPoolsWidget.js +++ b/sidecars/panel/src/components/widgets/QuotaPoolsWidget.js @@ -13,7 +13,12 @@ import { patchStyleVar, patchText, } from '../../core/domPatch.js'; -import { formatCountdown, formatTokens, formatUsd } from '../../core/formatters.js'; +import { + formatCountdown, + formatPctNumber, + formatTokens, + formatUsd, +} from '../../core/formatters.js'; import { createSvgIcon } from '../../icons/SvgIcon.js'; import { getEffectiveLocale, t } from '../../i18n/index.js'; @@ -189,8 +194,8 @@ function syncQuotaWindowMeter({ const resetStr = hasData ? formatCountdown(resetTime) : ''; if (hasData && rsvVal > 0) { - const rsvStr = rsvVal.toFixed(1); - const actualStr = actualVal.toFixed(1); + const rsvStr = formatPctNumber(rsvVal); + const actualStr = formatPctNumber(actualVal); const leases = Math.max(1, Number(leaseCount) || 1); const tipText = leases >= 2 @@ -198,13 +203,13 @@ function syncQuotaWindowMeter({ : t('quota.reservedTip', { rsv: rsvStr, actual: actualStr }); patchText( metaBeforeEl, - t('quota.usedBeforeReserved', { reset: resetStr, used: usedVal.toFixed(1) }) + t('quota.usedBeforeReserved', { reset: resetStr, used: formatPctNumber(usedVal) }) ); metaReservedEl.hidden = false; patchText(metaReservedEl, t('quota.reservedTag', { rsv: rsvStr })); patchAttr(metaReservedEl, 'title', tipText); metaAfterEl.hidden = false; - patchText(metaAfterEl, t('quota.usedAfterReserved', { rem: remVal.toFixed(1) })); + patchText(metaAfterEl, t('quota.usedAfterReserved', { rem: formatPctNumber(remVal) })); patchAttr(trackEl, 'title', tipText); const actualWidth = +Math.min(100, actualVal).toFixed(2); const rsvWidth = +Math.min(Math.max(0, 100 - actualWidth), rsvVal).toFixed(2); @@ -217,8 +222,8 @@ function syncQuotaWindowMeter({ hasData ? t('quota.usedAndLeft', { reset: resetStr, - used: usedVal.toFixed(1), - rem: remVal.toFixed(1), + used: formatPctNumber(usedVal), + rem: formatPctNumber(remVal), }) : fallbackMetaText ); diff --git a/sidecars/panel/src/core/formatters.js b/sidecars/panel/src/core/formatters.js index 7c520b9..413a55b 100644 --- a/sidecars/panel/src/core/formatters.js +++ b/sidecars/panel/src/core/formatters.js @@ -37,6 +37,26 @@ export function formatCachePct(value) { return `${num}%`; } +/** + * 格式化百分比数值文本:常规值保留 1 位小数,将边界值 `0.0` / `100.0` 收口为整数 `0` / `100`。 + * + * @param {number|string|null|undefined} value + * @param {{ withSymbol?: boolean }} [options] + * @returns {string} + */ +export function formatPctNumber(value, { withSymbol = false } = {}) { + const num = Number(value); + if (!Number.isFinite(num)) return withSymbol ? '0%' : '0'; + const rounded = Math.round(num * 10) / 10; + const str = + Math.abs(rounded) < 1e-9 + ? '0' + : Math.abs(rounded - 100) < 1e-9 + ? '100' + : rounded.toFixed(1); + return withSymbol ? `${str}%` : str; +} + export function getSpeedToneClass(tokPerSec) { return `tone-${classifySpeedTier(tokPerSec)}`; } diff --git a/sidecars/panel/src/core/reportExporter.js b/sidecars/panel/src/core/reportExporter.js index 9b4057d..1f4c3c2 100644 --- a/sidecars/panel/src/core/reportExporter.js +++ b/sidecars/panel/src/core/reportExporter.js @@ -8,6 +8,7 @@ import { formatAnomalyKindLabel, formatCompactDateTime, formatMetric, + formatPctNumber, formatSpeedMetric, formatTokensPrecise, formatUsd, @@ -429,10 +430,10 @@ export function buildStepsCsv(steps, { displaySettings = {}, includeBom = true } const promptTok = inTok + cacheTok; const cachePct = st.cacheHitPct != null && Number.isFinite(Number(st.cacheHitPct)) - ? Number(st.cacheHitPct).toFixed(1) + ? formatPctNumber(st.cacheHitPct) : promptTok > 0 - ? ((cacheTok / promptTok) * 100).toFixed(1) - : '0.0'; + ? formatPctNumber((cacheTok / promptTok) * 100) + : '0'; const ctxTok = Number(st.contextTokens || promptTok + outTok); const anomCount = Number(st.anomaly?.count || 0); const anomDesc = @@ -693,7 +694,7 @@ export function buildStepsMarkdownReport( const agg = summarizeStepsForExport(list, displaySettings); const totalTok = agg.sumIn + agg.sumCache + agg.sumOut; - const cacheHitPct = (computeCacheHitRatio(agg.sumIn, agg.sumCache) * 100).toFixed(1); + const cacheHitPct = formatPctNumber(computeCacheHitRatio(agg.sumIn, agg.sumCache) * 100); const avgTps = agg.tpsCnt > 0 ? formatSpeedMetric(agg.tpsSum / agg.tpsCnt, ' tok/s') : '—'; const avgTtft = agg.ttftCnt > 0 ? formatMetric(agg.ttftSum / agg.ttftCnt, 's') : '—'; const heading = title @@ -734,7 +735,9 @@ export function buildStepsMarkdownReport( ); for (const m of agg.sortedModels) { const mTotal = m.inTok + m.cacheTok + m.outTok; - const mCache = `${(computeCacheHitRatio(m.inTok, m.cacheTok) * 100).toFixed(1)}%`; + const mCache = formatPctNumber(computeCacheHitRatio(m.inTok, m.cacheTok) * 100, { + withSymbol: true, + }); const mTps = m.tpsCnt > 0 ? formatSpeedMetric(m.tpsSum / m.tpsCnt, ' tok/s') : '—'; lines.push( `| ${escapeMdCell(m.label)} | ${m.calls} | ${formatTokensPrecise(mTotal)} | ${mCache} | ${mTps} | ${formatUsd(m.cost, { precise: m.cost > 0 && m.cost < 0.1 })} |` @@ -835,7 +838,7 @@ export function buildConsumptionCsv( Number(acc.cacheReadTokens || 0), Number(acc.outputTokens || 0), Number(acc.totalTokens || 0), - Number(acc.cacheHitPct || 0).toFixed(1), + formatPctNumber(acc.cacheHitPct || 0), Number(acc.costUsd || 0).toFixed(4), `saved_usd=${Number(acc.savedCostUsd || 0).toFixed(4)}`, ]), @@ -851,7 +854,7 @@ export function buildConsumptionCsv( Number(m.cacheReadTokens || 0), Number(m.outputTokens || 0), Number(m.totalTokens || 0), - Number(m.cacheHitPct || 0).toFixed(1), + formatPctNumber(m.cacheHitPct || 0), Number(m.costUsd || 0).toFixed(4), m.avgTokPerSec != null ? `avg_tps=${Number(m.avgTokPerSec).toFixed(1)}` : '', ]) @@ -868,7 +871,7 @@ export function buildConsumptionCsv( Number(w.cacheReadTokens || 0), Number(w.responseTokens || 0) + Number(w.thinkingTokens || 0), Number(w.totalTokens || 0), - Number(w.cacheHitPct || 0).toFixed(1), + formatPctNumber(w.cacheHitPct || 0), Number(w.costUsd || 0).toFixed(4), `sessions=${Number(w.sessionCount || 0)}`, ]) @@ -885,7 +888,7 @@ export function buildConsumptionCsv( Number(c.cacheReadTokens || 0), Number(c.responseTokens || 0) + Number(c.thinkingTokens || 0), Number(c.totalTokens || 0), - Number(c.cacheHitPct || 0).toFixed(1), + formatPctNumber(c.cacheHitPct || 0), Number(c.costUsd || 0).toFixed(4), c.sourceName || c.appSource || '', ]) @@ -1433,14 +1436,14 @@ export function buildConsumptionMarkdownReport( '', `- **Total Tokens**: ${formatTokensPrecise(acc.totalTokens || 0)} (${Number(acc.calls || 0)} calls)`, `- **Est. Cost**: ${formatUsd(acc.costUsd || 0)} (Cache Saved ${formatUsd(acc.savedCostUsd || 0)})`, - `- **Cache Hit Rate**: ${Number(acc.cacheHitPct || 0).toFixed(1)}% (Input ${formatTokensPrecise(acc.inputTokens || 0)} / Cache ${formatTokensPrecise(acc.cacheReadTokens || 0)} / Output ${formatTokensPrecise(acc.outputTokens || 0)})`, + `- **Cache Hit Rate**: ${formatPctNumber(acc.cacheHitPct || 0, { withSymbol: true })} (Input ${formatTokensPrecise(acc.inputTokens || 0)} / Cache ${formatTokensPrecise(acc.cacheReadTokens || 0)} / Output ${formatTokensPrecise(acc.outputTokens || 0)})`, ] : [ `# 用量统计报告 · ${rangeLabel}`, '', `- **总 Token**: ${formatTokensPrecise(acc.totalTokens || 0)}(共 ${Number(acc.calls || 0)} 次调用)`, `- **预估费用**: ${formatUsd(acc.costUsd || 0)}(缓存节省 ${formatUsd(acc.savedCostUsd || 0)})`, - `- **缓存命中率**: ${Number(acc.cacheHitPct || 0).toFixed(1)}%(新输入 ${formatTokensPrecise(acc.inputTokens || 0)} / 缓存读取 ${formatTokensPrecise(acc.cacheReadTokens || 0)} / 输出 ${formatTokensPrecise(acc.outputTokens || 0)})`, + `- **缓存命中率**: ${formatPctNumber(acc.cacheHitPct || 0, { withSymbol: true })}(新输入 ${formatTokensPrecise(acc.inputTokens || 0)} / 缓存读取 ${formatTokensPrecise(acc.cacheReadTokens || 0)} / 输出 ${formatTokensPrecise(acc.outputTokens || 0)})`, ]; if (models.length > 0) { @@ -1455,7 +1458,7 @@ export function buildConsumptionMarkdownReport( ); for (const m of models) { lines.push( - `| ${escapeMdCell(m.displayText || m.label || m.shortName)} | ${Number(m.calls || 0)} | ${formatTokensPrecise(m.totalTokens || 0)} | ${Number(m.cacheHitPct || 0).toFixed(1)}% | ${m.avgTokPerSec != null ? formatSpeedMetric(m.avgTokPerSec, ' tok/s') : '—'} | ${formatUsd(m.costUsd || 0)} |` + `| ${escapeMdCell(m.displayText || m.label || m.shortName)} | ${Number(m.calls || 0)} | ${formatTokensPrecise(m.totalTokens || 0)} | ${formatPctNumber(m.cacheHitPct || 0, { withSymbol: true })} | ${m.avgTokPerSec != null ? formatSpeedMetric(m.avgTokPerSec, ' tok/s') : '—'} | ${formatUsd(m.costUsd || 0)} |` ); } } @@ -1472,7 +1475,7 @@ export function buildConsumptionMarkdownReport( ); for (const w of workspaces) { lines.push( - `| ${escapeMdCell(w.label || w.workspacePath || (en ? 'Unbound' : '未绑定工作区'))} | ${Number(w.sessionCount || 0)} | ${Number(w.calls || 0)} | ${formatTokensPrecise(w.totalTokens || 0)} | ${Number(w.cacheHitPct || 0).toFixed(1)}% | ${formatUsd(w.costUsd || 0)} |` + `| ${escapeMdCell(w.label || w.workspacePath || (en ? 'Unbound' : '未绑定工作区'))} | ${Number(w.sessionCount || 0)} | ${Number(w.calls || 0)} | ${formatTokensPrecise(w.totalTokens || 0)} | ${formatPctNumber(w.cacheHitPct || 0, { withSymbol: true })} | ${formatUsd(w.costUsd || 0)} |` ); } } @@ -1489,7 +1492,7 @@ export function buildConsumptionMarkdownReport( ); for (const c of sessions.slice(0, 8)) { lines.push( - `| ${escapeMdCell(c.title || c.cascadeId)} | ${Number(c.calls || 0)} | ${formatTokensPrecise(c.totalTokens || 0)} | ${Number(c.cacheHitPct || 0).toFixed(1)}% | ${formatUsd(c.costUsd || 0)} |` + `| ${escapeMdCell(c.title || c.cascadeId)} | ${Number(c.calls || 0)} | ${formatTokensPrecise(c.totalTokens || 0)} | ${formatPctNumber(c.cacheHitPct || 0, { withSymbol: true })} | ${formatUsd(c.costUsd || 0)} |` ); } } diff --git a/sidecars/panel/src/core/stepInspector.js b/sidecars/panel/src/core/stepInspector.js index ed6ff3b..af59555 100644 --- a/sidecars/panel/src/core/stepInspector.js +++ b/sidecars/panel/src/core/stepInspector.js @@ -8,6 +8,7 @@ import { formatAnomalyKindLabel, formatCompactDateTime, formatMetric, + formatPctNumber, formatSpeedMetric, formatTimingDetailSec, formatTokensPrecise, @@ -267,10 +268,12 @@ export function buildStepDiagnosticMarkdown( const promptTok = Number(st.inputTokens || 0) + Number(st.cacheReadTokens || 0); const cachePct = st.cacheHitPct != null && Number.isFinite(Number(st.cacheHitPct)) - ? `${Number(st.cacheHitPct).toFixed(1)}%` + ? formatPctNumber(st.cacheHitPct, { withSymbol: true }) : promptTok > 0 - ? `${((Number(st.cacheReadTokens || 0) / promptTok) * 100).toFixed(1)}%` - : '0.0%'; + ? formatPctNumber((Number(st.cacheReadTokens || 0) / promptTok) * 100, { + withSymbol: true, + }) + : '0%'; const ctxTok = Number(st.contextTokens || promptTok + Number(st.outputTokens || 0)); const ctxDelta = prevContextTokens != null && ctxTok > 0 diff --git a/sidecars/panel/src/views/ConsumptionView.js b/sidecars/panel/src/views/ConsumptionView.js index fa4563f..deeeb4e 100644 --- a/sidecars/panel/src/views/ConsumptionView.js +++ b/sidecars/panel/src/views/ConsumptionView.js @@ -23,6 +23,7 @@ import { formatCnyApprox, formatDateSpanBadge, formatMetric, + formatPctNumber, formatSpeedMetric, formatTokensPrecise, formatUsd, @@ -813,7 +814,7 @@ export const ConsumptionView = defineComponent({ responseTokens, outputTokens: responseTokens + thinkingTokens, tokText: formatTokensPrecise(tok), - pctText: `${pct.toFixed(1)}%`, + pctText: formatPctNumber(pct, { withSymbol: true }), color, isOther: false, }; @@ -850,7 +851,7 @@ export const ConsumptionView = defineComponent({ responseTokens: otherResp, outputTokens: otherResp + otherThink, tokText: formatTokensPrecise(otherTok), - pctText: `${otherPct.toFixed(1)}%`, + pctText: formatPctNumber(otherPct, { withSymbol: true }), color: 'var(--cons-other-seg)', isOther: true, }); @@ -1014,7 +1015,7 @@ export const ConsumptionView = defineComponent({ : promptTok > 0 && Number(item.cacheReadTokens || 0) > 0 ? +((Number(item.cacheReadTokens || 0) / promptTok) * 100).toFixed(1) : 0; - const cachePctStr = cachePctVal.toFixed(1); + const cachePctStr = formatPctNumber(cachePctVal); const effCostPer1M = !isAllUnpriced && costVal > 0 && total >= 1000 ? costVal / (total / 1_000_000) : null; const outTok = Number( @@ -1028,7 +1029,7 @@ export const ConsumptionView = defineComponent({ const barPct = costBase > 0 && costVal > 0 ? Math.min(100, Math.max(1, (costVal / costBase) * 100)) : 0; patchAttr(refs.pctBadge, 'hidden', false); patchAttr(refs.pctBadge, 'title', null); - patchText(refs.pctBadge, `${costShare.toFixed(1)}%`); + patchText(refs.pctBadge, formatPctNumber(costShare, { withSymbol: true })); patchText(refs.totalTokEl, isAllUnpriced ? '' : formatCnyApprox(costVal)); patchText(refs.costEl, costText); @@ -1103,7 +1104,7 @@ export const ConsumptionView = defineComponent({ callsBase > 0 && callsCount > 0 ? Math.min(100, Math.max(1, (callsCount / callsBase) * 100)) : 0; patchAttr(refs.pctBadge, 'hidden', false); patchAttr(refs.pctBadge, 'title', null); - patchText(refs.pctBadge, `${callsShare.toFixed(1)}%`); + patchText(refs.pctBadge, formatPctNumber(callsShare, { withSymbol: true })); patchText(refs.totalTokEl, formatTokensPrecise(total)); patchText(refs.costEl, t('cons.callsCount', { calls: callsCount })); @@ -1143,7 +1144,7 @@ export const ConsumptionView = defineComponent({ grandTotalTokens > 0 && total > 0 ? Math.min(1, Math.max(0.008, total / grandTotalTokens)) : 0; patchAttr(refs.pctBadge, 'hidden', false); patchAttr(refs.pctBadge, 'title', null); - patchText(refs.pctBadge, `${share.toFixed(1)}%`); + patchText(refs.pctBadge, formatPctNumber(share, { withSymbol: true })); patchText(refs.totalTokEl, formatTokensPrecise(total)); patchText(refs.costEl, costText); @@ -1317,7 +1318,7 @@ export const ConsumptionView = defineComponent({ const share = grandTotalTokens > 0 ? +((total / grandTotalTokens) * 100).toFixed(1) : 0; const scaleRatio = grandTotalTokens > 0 && total > 0 ? Math.min(1, Math.max(0.01, total / grandTotalTokens)) : 0; - patchText(refs.pctBadge, `${share.toFixed(1)}%`); + patchText(refs.pctBadge, formatPctNumber(share, { withSymbol: true })); patchText(refs.totalTokEl, formatTokensPrecise(total)); const costVal = Number(item.costUsd || 0); @@ -1568,7 +1569,7 @@ export const ConsumptionView = defineComponent({ ? Math.min(1, Math.max(0.01, total / tokBase)) : 0; - patchText(refs.pctBadge, `${share.toFixed(1)}%`); + patchText(refs.pctBadge, formatPctNumber(share, { withSymbol: true })); if (sortMode === 'tokens') { patchText(refs.totalTokEl, costText); patchText(refs.costEl, formatTokensPrecise(total)); @@ -1638,7 +1639,7 @@ export const ConsumptionView = defineComponent({ if (showFallbackMeta) { const srcLabel = item.sourceName || item.appSource || ''; const cacheLabel = t('cons.topConvCacheMeta', { - pct: Number(item.cacheHitPct ?? 0).toFixed(1), + pct: formatPctNumber(item.cacheHitPct ?? 0), }); patchText(refs.fallbackMetaEl, srcLabel ? `${srcLabel} · ${cacheLabel}` : cacheLabel); } @@ -1755,7 +1756,7 @@ export const ConsumptionView = defineComponent({ patchText(heroCostUsd, formatUsd(costUsd)); patchText(heroCostCny, formatCnyApprox(costUsd)); - patchText(cacheHitPctEl, `${Number(acct.cacheHitPct ?? 0).toFixed(1)}%`); + patchText(cacheHitPctEl, formatPctNumber(acct.cacheHitPct ?? 0, { withSymbol: true })); patchText(cacheTokensEl, t('cons.cacheHitTokens', { tokens: formatTokensPrecise(cacheTokens) })); let inPct = 0; diff --git a/sidecars/panel/src/views/StepsDetailView.js b/sidecars/panel/src/views/StepsDetailView.js index b40a5da..00bd223 100644 --- a/sidecars/panel/src/views/StepsDetailView.js +++ b/sidecars/panel/src/views/StepsDetailView.js @@ -20,6 +20,7 @@ import { formatAnomalyTagText, formatCompactDateTime, formatMetric, + formatPctNumber, formatSpeedMetric, formatTimingDetailSec, formatTokens, @@ -755,7 +756,7 @@ export const StepsDetailView = defineComponent({ patchText(inspKpiCache.lbl, t('steps.inspCacheLabel')); patchText(inspKpiCache.val, formatTokensPrecise(cacheTok)); - patchText(inspKpiCache.sub, `${cachePct.toFixed(1)}%`); + patchText(inspKpiCache.sub, formatPctNumber(cachePct, { withSymbol: true })); patchText(inspKpiOutput.lbl, t('steps.inspOutputLabel')); patchText(inspKpiOutput.val, formatTokensPrecise(outTok)); diff --git a/sidecars/panel/test/quota-pools.test.mjs b/sidecars/panel/test/quota-pools.test.mjs index 10383ca..7c8aa32 100644 --- a/sidecars/panel/test/quota-pools.test.mjs +++ b/sidecars/panel/test/quota-pools.test.mjs @@ -801,3 +801,18 @@ test('argon_weekly capsule & CLI slot enables only when user has an Argon weekly ); assert.doesNotMatch(cliUltra, /A周/); }); + +test('formatPctNumber collapses boundary 0.0 -> 0 and 100.0 -> 100 while preserving intermediate decimals', async () => { + const { formatPctNumber } = await import('../src/core/formatters.js'); + assert.equal(formatPctNumber(0), '0'); + assert.equal(formatPctNumber(0, { withSymbol: true }), '0%'); + assert.equal(formatPctNumber(0.04, { withSymbol: true }), '0%'); + assert.equal(formatPctNumber(-0.01, { withSymbol: true }), '0%'); + assert.equal(formatPctNumber(100), '100'); + assert.equal(formatPctNumber(100, { withSymbol: true }), '100%'); + assert.equal(formatPctNumber(99.96, { withSymbol: true }), '100%'); + assert.equal(formatPctNumber(0.5, { withSymbol: true }), '0.5%'); + assert.equal(formatPctNumber(1.0, { withSymbol: true }), '1.0%'); + assert.equal(formatPctNumber(50.0, { withSymbol: true }), '50.0%'); + assert.equal(formatPctNumber(99.9, { withSymbol: true }), '99.9%'); +});