@philiprehberger/money-ts
v0.1.4
Published
Precise money and currency arithmetic
Downloads
57
Readme
@philiprehberger/money-ts
Precise money and currency arithmetic
Installation
npm install @philiprehberger/money-tsUsage
import { money } from '@philiprehberger/money-ts';
const price = money(1099, 'USD');
const tax = price.percentage(8.5);
const total = price.add(tax);
total.format(); // "$11.92"
total.format('de-DE'); // "11,92 $"
const [a, b] = total.allocate([60, 40]); // handles remaindersFrom Decimal
import { money } from '@philiprehberger/money-ts';
const price = money.fromDecimal(10.99, 'USD');
price.toCents(); // 1099API
| Method | Description |
|--------|-------------|
| money(cents, currency) | Create from minor units |
| money.fromDecimal(decimal, currency) | Create from decimal |
| .add(other) / .subtract(other) | Arithmetic (same currency) |
| .multiply(n) / .divide(n) / .percentage(pct) | Scaling |
| .allocate(ratios) | Split with remainder handling |
| .format(locale?) | Intl.NumberFormat currency string |
| .toDecimal() / .toCents() | Conversion |
| .equals() / .greaterThan() / .lessThan() | Comparison |
Development
npm install
npm run build
npm testSupport
If you find this project useful:
