Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
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.
Bad example
| 1 | const label = `${(amount / 100).toFixed(2)} €`; |
Explanation (EN)
Hand-built labels can use the wrong separators, symbol position or precision.
Objašnjenje (HR)
Good example
| 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)
Notes (EN)
Format for the requested locale/currency with an existing reusable Intl formatter, keeping storage units and arithmetic rounding separate.
Exceptions / Tradeoffs (EN)
Currencies have different minor-unit scales and fraction defaults. Intl formatting does not repair floating-point arithmetic or parse input; custom business rounding/display policies still need explicit options and tests.