Financial Math & Currency Handling Skill
This skill governs how monetary values are handled in the Midas Web Concept project.
🚨 ZERO TOLERANCE RULES
- •NO FLOATING POINTS: Never use standard JavaScript
numbertype for financial calculations. - •LIBRARY USAGE: Always use
decimal.js(client-side) orPrisma.Decimal(server-side/DB). - •CURRENCY ISOLATION: Never add/subtract values of different currencies (e.g.,
USD + TRY).
🛠 Implementation Guidelines
1. Database & Type Definition
- •In
schema.prisma, all monetary fields must beDecimal(19, 4). - •In TypeScript interfaces, map these fields to
Decimalorstring(nevernumber).
2. Calculation Pattern
When calculating Portfolio Value or Trade Totals:
typescript
import Decimal from 'decimal.js'; // BAD ❌ const total = price * quantity; // GOOD ✅ const priceDec = new Decimal(price); const qtyDec = new Decimal(quantity); const total = priceDec.times(qtyDec);