Decimal provides support for correct rounded floating point arithmetic, unlike the standard Number type. It also supports user-defined precision (default is 20 decimal places), which can be as large as needed.
Decimal
Number
Returns a new Decimal instance from the value or 0.
0
Optional
Static
Returns a new Decimal that is the sum of this and x.
x
let a = decimal('50000000000')let b = decimal('0.000000005')a.add(b) // 50000000000.000000005
Returns a new copy of this Decimal value.
Returns a comparison value representing the ordering of this value in respect to x.
-1
1
Returns a new Decimal that is the quotient of this and x
let a = decimal('1')let b = decimal('3')a.div(b) // 0.333333333333333333333333333333
Returns true if this value is equal to the value of x, otherwise false.
true
false
other
Returns true if this value is greater than the value of x, otherwise false.
Returns true if this value is greater than or equal to the value of x, otherwise false.
Returns true if this value is less than the value of x, otherwise false.
Returns true if this value is less than or equal to the value of x, otherwise false.
Returns a new Decimal that is the product of this and x.
let a = decimal('0.0000000000000000000025')let b = decimal('400000000000000000000')a.mul(b) // 1
Returns a new Decimal that has the opposite sign of this Decimal.
let a = decimal('5')a.negated() // -5
Returns the square root of this Decimal.
Returns a new Decimal that is the difference between this and x.
let a = decimal('1')let b = decimal('0.0000000000000000001')a.sub(b) // 0.9999999999999999999
Converts this decimal to the Number value
Returns a string representation of this decimal.
Generated using TypeDoc
Decimal
provides support for correct rounded floating point arithmetic, unlike the standardNumber
type. It also supports user-defined precision (default is 20 decimal places), which can be as large as needed.