Class: BigDecimal

types~BigDecimal(unscaledValue, scale)

The BigDecimal class provides operations for arithmetic, scale manipulation, rounding, comparison and format conversion. The #toString method provides a canonical representation of a BigDecimal.

Constructor

new BigDecimal(unscaledValue, scale)

Constructs an immutable arbitrary-precision signed decimal number. A BigDecimal consists of an arbitrary precision integer unscaled value and a 32-bit integer scale. If zero or positive, the scale is the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the scale. The value of the number represented by the BigDecimal is therefore (unscaledValue × 10-scale).

Parameters:
Name Type Description
unscaledValue Integer | Number

The integer part of the decimal.

scale Number

The scale of the decimal.

Source:

Methods

add(other) → (non-null) {BigDecimal}

Returns the sum of this and the given BigDecimal.

Parameters:
Name Type Description
other BigDecimal

The BigDecimal to sum to this.

Source:
Returns:

The BigDecimal result.

Type
BigDecimal

compare(other) → {number}

Compares this BigDecimal with the given one.

Parameters:
Name Type Description
other BigDecimal

Integer to compare against.

Source:
Returns:

0 if they are the same, 1 if the this is greater, and -1 if the given one is greater.

Type
number

equals(other) → {Boolean}

Returns true if the value of the BigDecimal instance and other are the same

Parameters:
Name Type Description
other BigDecimal
Source:
Returns:
Type
Boolean

greaterThan(other) → {boolean}

Returns true if the current instance is greater than the other

Parameters:
Name Type Description
other BigDecimal
Source:
Returns:
Type
boolean

isNegative() → {boolean}

Source:
Returns:

Whether this value is negative.

Type
boolean

isZero() → {boolean}

Source:
Returns:

Whether this value is zero.

Type
boolean

notEquals(other) → {boolean}

Parameters:
Name Type Description
other BigDecimal
Source:
Returns:
Type
boolean

subtract(other) → (non-null) {BigDecimal}

Returns the difference of this and the given BigDecimal.

Parameters:
Name Type Description
other BigDecimal

The BigDecimal to subtract from this.

Source:
Returns:

The BigDecimal result.

Type
BigDecimal

toJSON()

Returns the string representation. Method used by the native JSON.stringify() to serialize this instance.

Source:

toNumber() → {Number}

Returns a Number representation of this BigDecimal.

Source:
Returns:
Type
Number

toString() → {string}

Returns the string representation of this BigDecimal

Source:
Returns:
Type
string

(static) fromBuffer(buf) → {BigDecimal}

Returns the BigDecimal representation of a buffer composed of the scale (int32BE) and the unsigned value (varint BE)

Parameters:
Name Type Description
buf Buffer
Source:
Returns:
Type
BigDecimal

(static) fromNumber(value) → {BigDecimal}

Returns a BigDecimal representation of the Number

Parameters:
Name Type Description
value Number
Source:
Returns:
Type
BigDecimal

(static) fromString(value) → {BigDecimal}

Returns a BigDecimal representation of the string

Parameters:
Name Type Description
value String
Source:
Returns:
Type
BigDecimal

(static) toBuffer(value) → {Buffer}

Returns a buffer representation composed of the scale as a BE int 32 and the unsigned value as a BE varint

Parameters:
Name Type Description
value BigDecimal
Source:
Returns:
Type
Buffer