Browse documentation

Money

Represents a monetary amount in integer cents and provides arithmetic operations.

Table of contents

Category

Value

Import

js
import { Money } from "valyrian.js/money";

Public signature

ts
Money.fromCents(cents: number): Money
Money.fromDecimal(value: number, decimalPlaces?: number): Money

API form

Money is a class with a private constructor. Obtain values through Money.fromCents(...) or Money.fromDecimal(...).

Methods

ts
Money.fromDecimal(value: number, decimalPlaces = 2): Money
toCents(): number
toDecimal(decimalPlaces = 2): number
add(other: Money): Money
subtract(other: Money): Money
multiply(multiplier: number): Money
divide(divider: number): Money

Numeric behavior

fromCents() truncates fractional cents. fromDecimal() and arithmetic operations round to integer cents. divide() throws when the divisor is zero.

Errors

Division throws when the divisor is zero.