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).
fullstack ruleP0universalStack: javascript
parsingnumbersi18ncorrectnessdata-integrity
Don't misread a thousands separator as a decimal point when parsing numbers
A locale-aware number parser must not assume a single dot/comma is always a decimal separator; a separator followed by exactly three digits is a thousands group, so guard against silently dividing values by ~1000.
PR: vinify-frontend · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codets
| 1 | // '1.234' -> 1.234 (wrong; should be 1234) |
| 2 | function normalize(s) { |
| 3 | return parseFloat(s.replace(',', '.')); |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | function normalize(raw) { |
| 2 | const digits = raw.replace(/[^\d.,-]/g, ''); |
| 3 | // single separator + exactly 3 trailing digits => thousands group |
| 4 | if (/^-?\d+[.,]\d{3}$/.test(digits)) return Number(digits.replace(/[.,]/, '')); |
| 5 | return Number(digits.replace(',', '.')); |
| 6 | } |
Explanation (EN)
Objašnjenje (HR)