Money
Represents a monetary amount in integer cents and provides arithmetic operations.
Table of contents
Category
Value
Import
jsimport { Money } from "valyrian.js/money";Public signature
tsMoney.fromCents(cents: number): Money
Money.fromDecimal(value: number, decimalPlaces?: number): MoneyAPI form
Money is a class with a private constructor. Obtain values through Money.fromCents(...) or Money.fromDecimal(...).
Methods
tsMoney.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): MoneyNumeric 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.