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).
backend ruleP1universalStack: javascript
correctnessmathedge-cases
Guard percentage/ratio math against tiny or zero denominators
Dividing by a value close to zero produces absurd results; decide and document the fallback (null, capped value) instead of returning huge numbers.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetypescript
| 1 | return ((current - previous) / Math.abs(previous)) * 100; // previous ~ 0 -> 999999999 |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | if (previous === 0) return null; // or a defined capped value |
| 2 | return ((current - previous) / Math.abs(previous)) * 100; |
Explanation (EN)
Objašnjenje (HR)