Class: BigDecimal

types~ BigDecimal

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.

Methods

(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
Returns:
Type
BigDecimal

(static) fromNumber(value) → {BigDecimal}

Returns a BigDecimal representation of the Number
Parameters:
Name Type Description
value Number
Returns:
Type
BigDecimal

(static) fromString(value) → {BigDecimal}

Returns a BigDecimal representation of the string
Parameters:
Name Type Description
value String
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
Returns:
Type
Buffer

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.
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.
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
Returns:
Type
Boolean

greaterThan(other) → {boolean}

Returns true if the current instance is greater than the other
Parameters:
Name Type Description
other BigDecimal
Returns:
Type
boolean

isNegative() → {boolean}

Returns:
Whether this value is negative.
Type
boolean

isZero() → {boolean}

Returns:
Whether this value is zero.
Type
boolean

notEquals(other) → {boolean}

Parameters:
Name Type Description
other BigDecimal
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.
Returns:
The BigDecimal result.
Type
BigDecimal

toJSON()

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

toNumber() → {Number}

Returns a Number representation of this BigDecimal.
Returns:
Type
Number

toString() → {string}

Returns the string representation of this BigDecimal
Returns:
Type
string