Financial Calculations Guide
Always use minor units (cents/paisa) for money calculations.
Money Type
interface Money {
amount: number; // In minor units
currency: string;
}
Constants
Use constants from shared/financial-constants.ts:
import { DAYS_PER_YEAR, BASIS_POINTS_SCALE } from "@shared/financial-constants";
Utilities
Use utilities from shared/financial-calculations.ts:
import { applyBpsToMinor } from "@shared/financial-calculations";
const fee = applyBpsToMinor(1000000, 250); // 2.5% of amount
Why Minor Units?
Avoids floating-point precision errors:
// ❌ BAD
const total = 10.1 + 0.2; // 10.299999999999999
// ✅ GOOD
const total = 1010 + 20; // 1030