Banker's rounding (round-half-to-even) for interest calculations
Why it matters
Standard Math.round() always rounds 0.5 upward, introducing a systematic positive bias in interest calculations. Over millions of compounding periods this bias is non-trivial and legally relevant — financial regulators and ISO 25010 functional-correctness standards expect rounding to be demonstrably unbiased. Banker's rounding (round-half-to-even) is the industry standard because it distributes rounding error evenly across the dataset. CWE-682 covers this class of incorrect calculation leading to incorrect financial results.
Severity rationale
High because systematic rounding bias in interest accrual produces incorrect balances at scale, creating regulatory exposure and customer disputes.
Remediation
Replace bare Math.round() calls in financial calculation logic with a banker's rounding implementation or a library that supports ROUND_HALF_EVEN. Centralize this in src/lib/finance.ts.
// src/lib/finance.ts
import Decimal from 'decimal.js';
export function roundToNearestCent(value: number): number {
return new Decimal(value)
.toDecimalPlaces(2, Decimal.ROUND_HALF_EVEN)
.toNumber();
}
Search for all Math.round, .toFixed, and Math.ceil calls in src/ and replace with roundToNearestCent() for any interest, APY, or fee calculation.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Financial Form Validation Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-682 — Incorrect Calculation
- iso-25010:2011 · functional-correctness — Functional Suitability — Functional Correctness
Taxons
History
- 2026-04-18·v1.0.0·Initial import from finserv-form-validation·automated