Introduction
Units is a TypeScript library family for exact-arithmetic financial calculations using BigInt rationals.
Every number is stored as a numerator / denominator pair of BigInts — no floats, no rounding errors, no silent precision loss.
Why?
// JavaScript floats
0.1 + 0.2 === 0.3 // false
// @table-q/units
GBP('0.10').add('0.20').eq('0.30') // true
Financial software cannot tolerate floating-point errors. @table-q/units eliminates them at the representation level.
Packages
| Package | Description |
|---|---|
@table-q/units | Core library — units, values, arithmetic, rounding |
@table-q/units-plugin-bignumber | BigNumber.js integration for sqrt, log, etc. |
Quick Start
npm install @table-q/units
import { SCALAR } from '@table-q/units';
const GBP = SCALAR.clone({ kind: 'GBP', decimals: 2, signed: true });
const a = GBP('10.50');
const b = GBP('3.25');
console.log(a.add(b).toDecimal()); // '13.75'
console.log(a.div('3').mul('3').eq(a)); // true — exact fractions