Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP2universalStack: JavaScript
i18nformattingmoney
Format currency and numbers with Intl.NumberFormat
Use `Intl.NumberFormat` (a shared, memoized instance) for currency, decimals and locale-aware number formatting instead of hand-rolled string concatenation. It handles locale separators, currency symbols and rounding correctly. Constructing a formatter per call is slow, so reuse one.
PR: profico-org-corpus batch2 (all stacks/products)Created: Jul 26, 2026
Bad example
Old codets
| 1 | const label = `${(amount / 100).toFixed(2)} €`; |
Explanation (EN)
Hardcodes the separator, symbol placement and grouping; wrong for most locales.
Objašnjenje (HR)
Good example
New codets
| 1 | const eur = new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }); |
| 2 | const label = eur.format(amount / 100); |
Explanation (EN)
One reused formatter renders the correct locale-aware currency string.
Objašnjenje (HR)