Interest/APY rounded consistently
Why it matters
Two calculation sites that both compute interest but use different rounding functions — one Math.round(), one Math.floor() — will produce different balances for identical inputs. The discrepancy shows up as a mismatch between the displayed APY and the actual accrued interest, leading to customer disputes and reconciliation failures. CWE-682 covers incorrect financial calculation; ISO 25010 maintainability requires that the same logical operation produce the same result regardless of call site.
Severity rationale
Low because inconsistent rounding accumulates slowly and typically surfaces only during reconciliation or customer disputes, not as immediate transaction failures.
Remediation
Centralize interest rounding into a single exported function in src/lib/finance.ts and replace every direct Math.round / Math.floor / .toFixed call in financial logic with it.
// src/lib/finance.ts
import Decimal from 'decimal.js';
/** Canonical rounding for all interest / APY calculations. */
export function roundInterestCents(value: number): number {
return new Decimal(value)
.toDecimalPlaces(0, Decimal.ROUND_HALF_EVEN)
.toNumber();
}
Search src/ for Math.round, Math.floor, and .toFixed within files that reference interest, apy, or rate, and replace each with roundInterestCents().
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 · maintainability — Maintainability — Consistency
Taxons
History
- 2026-04-18·v1.0.0·Initial import from finserv-form-validation·automated