Skip to content

fix(pulse): fmtHero renders negative amounts as unabridged digits - #1778

Closed
takanorinishida wants to merge 1 commit into
danielmiessler:mainfrom
takanorinishida:fix/pulse-finance-hero-sign
Closed

fix(pulse): fmtHero renders negative amounts as unabridged digits#1778
takanorinishida wants to merge 1 commit into
danielmiessler:mainfrom
takanorinishida:fix/pulse-finance-hero-sign

Conversation

@takanorinishida

Copy link
Copy Markdown

fmtHero()'s magnitude thresholds (>= 1_000_000, >= 10_000, >= 1_000) are checked against the signed value, so any negative number fails every branch and falls through to the last one, which was written assuming n was already known-small. Net (Overall tab) commonly goes negative when spending exceeds income, so a K/M-abbreviated sibling KPI like "$2.1M" ends up next to "$-2,120,000" instead of "-$2.1M".

Fix

Threshold on Math.abs(n) instead and prepend the sign once, before the currency symbol.

Non-destructive

Positive inputs are byte-identical (sign is the empty string); this only changes output for values that were already rendering as long unformatted digit strings.

Verification

Standalone checks: fmtHero(2120000)$2.1M (unchanged), fmtHero(-2120000)-$2.1M (was $-2,120,000), plus the K/thousands/zero boundary cases, all matching.

🤖 Generated with Claude Code

fmtHero()'s magnitude thresholds (>= 1_000_000, >= 10_000, >= 1_000) are
checked against the signed value, so any negative number fails every
branch and falls through to the last one, which was written assuming
n was already known-small. Net (Overall tab) commonly goes negative
when spending exceeds income, so a K/M-abbreviated sibling KPI like
"$2.1M" ends up next to "$-2,120,000" instead of "-$2.1M".

Threshold on Math.abs(n) instead and prepend the sign once, before
the currency symbol. Positive inputs are byte-identical (sign is the
empty string); this only changes output for values that were already
rendering as long unformatted digit strings.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NVzLJHrJPj5Phmh1vaLUBV
@danielmiessler

Copy link
Copy Markdown
Owner

Thanks @takanorinishida — the fmtHero negative-amount abridging fix. Ported into the source tree (the public repo is generated from it, so I'm closing this here), credited by number at the fix site. Ships in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants