money-safe
v0.1.0TYPE-SAFE MONEY
DOCS INTERFACE · GUIDE / RECIPES / REFERENCE · MINOR UNITS STAY EXPLICIT
Migration from Number

Migration from Number

Some existing systems already pass decimal numbers.

Use fromNumber at the boundary and choose the rounding mode there:

ts
import { amount } from '@crapthings/money-safe';

const value = amount.fromNumber(19.995, 'USD', {
  rounding: 'half-up'
});

value.toDecimal();
// '20.00'

Move new code toward decimal strings or minor units:

ts
amount('19.99', 'USD');
amount.minor(1999, 'USD');