Skip to content

Amount

This class defines an Amount for arbitrary-precision decimal arithmetic.

It inherits methods from big.js library

Constructors

Constructor

new Amount(n): Amount;

The Amount constructor.

Parameters

ParameterTypeDescription
nstring | number | AmountThe number, string, or Amount to initialize with

Returns

Amount

Methods

abs()

abs(): Amount;

Returns an absolute Amount.

Returns

Amount

The absolute value as a new Amount


cmp()

cmp(n): -1 | 0 | 1;

Compares this Amount with another value.

Parameters

ParameterTypeDescription
nstring | number | AmountThe value to compare with

Returns

-1 | 0 | 1

-1 if less than, 0 if equal, 1 if greater than


div()

div(n): Amount;

Divides this Amount by another value.

Parameters

ParameterTypeDescription
nstring | number | AmountThe divisor value

Returns

Amount

The division result as a new Amount


eq()

eq(n): boolean;

Checks if this Amount equals another value.

Parameters

ParameterTypeDescription
nstring | number | AmountThe value to compare with

Returns

boolean

True if equal, false otherwise


gt()

gt(n): boolean;

Checks if this Amount is greater than another value.

Parameters

ParameterTypeDescription
nstring | number | AmountThe value to compare with

Returns

boolean

True if greater than, false otherwise


gte()

gte(n): boolean;

Checks if this Amount is greater than or equal to another value.

Parameters

ParameterTypeDescription
nstring | number | AmountThe value to compare with

Returns

boolean

True if greater than or equal, false otherwise


lt()

lt(n): boolean;

Checks if this Amount is less than another value.

Parameters

ParameterTypeDescription
nstring | number | AmountThe value to compare with

Returns

boolean

True if less than, false otherwise


lte()

lte(n): boolean;

Checks if this Amount is less than or equal to another value.

Parameters

ParameterTypeDescription
nstring | number | AmountThe value to compare with

Returns

boolean

True if less than or equal, false otherwise


minus()

minus(n): Amount;

Subtracts another value from this Amount.

Parameters

ParameterTypeDescription
nstring | number | AmountThe value to subtract

Returns

Amount

The difference as a new Amount


mod()

mod(n): Amount;

Calculates the modulo (remainder) of dividing this Amount by another value.

Similar to % operator

Parameters

ParameterTypeDescription
nstring | number | AmountThe divisor value

Returns

Amount

The remainder as a new Amount


plus()

plus(n): Amount;

Adds another value to this Amount.

Parameters

ParameterTypeDescription
nstring | number | AmountThe value to add

Returns

Amount

The sum as a new Amount


round()

round(dp?): Amount;

Rounds this Amount to a maximum of dp decimal places.

Parameters

ParameterTypeDescription
dp?numberThe number of decimal places (optional)

Returns

Amount

The rounded value as a new Amount


times()

times(n): Amount;

Multiplies this Amount by another value.

Parameters

ParameterTypeDescription
nstring | number | AmountThe value to multiply by

Returns

Amount

The product as a new Amount


toFixed()

toFixed(dp?): string;

Returns a string representing the value of this Amount in normal notation to a fixed number of decimal places.

Parameters

ParameterTypeDescription
dp?numberThe number of decimal places (optional)

Returns

string

The formatted string representation


toNumber()

toNumber(): number;

Returns a primitive number representing the value of this Amount.

Returns

number

The numeric value of this Amount


toString()

toString(): string;

Returns a string representing the value of this Amount.

Returns

string

The string representation of this Amount