fix(FN-7786): hide sub-cent partial costs

Fusion-Task-Id: FN-7786
This commit is contained in:
gsxdsm
2026-07-10 23:43:53 -07:00
parent 9bed076ab0
commit 7d29367bc5
2 changed files with 6 additions and 1 deletions

View File

@@ -86,6 +86,8 @@ describe("Command Center cost formatting", () => {
expect(formatCost(12.5, false)).toBe("$12.50");
expect(formatCost(0, false)).toBe("$0.00");
expect(formatCost(0, true)).toBe("—");
expect(formatCost(0.004, true)).toBe("—");
expect(formatCost(0.01, true)).toBe("$0.01+");
expect(formatCost(null, true)).toBe("—");
});
});

View File

@@ -53,9 +53,12 @@ export function formatDurationMs(ms: number | null): string {
*
* FNXC:CommandCenterCost 2026-07-10-23:35:
* A zero subtotal is exact only when every contribution is priced. Mixed pricing with a zero known subtotal must remain `—`, because `$0.00+` suggests a meaningful lower bound while all positive cost may belong to unpriced usage.
*
* FNXC:CommandCenterCost 2026-07-10-23:39:
* Apply the mixed-zero rule at displayed cent precision so a positive sub-cent subtotal cannot leak through as `$0.00+`. A partial subtotal becomes meaningful only when it rounds to at least one visible cent.
*/
export function formatCost(usd: number | null, unavailable: boolean): string {
if (usd === null || !Number.isFinite(usd) || (unavailable && usd === 0)) {
if (usd === null || !Number.isFinite(usd) || (unavailable && Math.round(usd * 100) === 0)) {
return "—";
}
const formatted = `$${usd.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;