Creates a new Decimal value by parsing the provided text.
An Ion-encoded decimal value.
Creates a new Decimal value using the provided coefficient and exponent values.
See the class-level Decimal documentation for details.
See the class-level Decimal documentation for details.
Creates a new Decimal value using the provided coefficient and exponent values.
Because the BigInt data type cannot represent -0, a third parameter called isNegative
may be supplied
to explicitly set the sign of the Decimal following construction. If this flag is not specified,
the provided coefficient's sign will be used. If isNegative is specified but is not in agreement with
the coefficient's sign, the value of isNegative takes precedence.
See the class-level Decimal documentation for details.
See the class-level Decimal documentation for details.
Must be set to 'true' when constructing -0. May be omitted otherwise.
Compares this Decimal with another and returns -1, 0, or 1 if this Decimal is less than, equal to, or greater than the other Decimal.
Note that a return value of 0 doesn't guarantee that equals() would return true, as compareTo() doesn't require the values to have the same precision to be considered equal, whereas equals() does. Additionally, compareTo() treats 0. and -0. as equal, but equals() does not.
Compares this Decimal with another and returns true if they are equivalent in value and precision; otherwise returns false. Note that this differs from compareTo(), which doesn't require precision to match when returning 0.
Returns a BigInt representing the coefficient of this Decimal value.
Note that the BigInt data type is unable to represent -0 natively. If you wish to check for a -0 coefficient, test whether the coefficient is zero and then call isNegative.
Returns a number representing the exponent of this Decimal value.
Returns a number representing the integer portion of this Decimal. Any fractional portion of this Decimal is truncated.
Returns true if this Decimal is negative; otherwise false.
Returns a number representing the value of this Decimal. Note that some Decimal (base-10) values cannot be precisely expressed in JavaScript's base-2 number type.
Converts this Decimal value to a JSON number when being serialized via JSON.stringify()
.
Returns a string representation of this Decimal, using exponential notation when appropriate.
Given a string containing the Ion text representation of a decimal value, returns a new Decimal object corresponding to the value. If a string such as '5' is provided, a 'd0' suffix is assumed.
This class provides the additional semantics necessary for decimal values.
Unlike IEEE-754 floating point representation, Decimal values can represent numeric values without loss of precision. Each number is stored as a pair of integers, a "coefficient" and an "exponent", which can be combined to calculate the original value using the following formula:
Here are some examples:
Presently, the supported range of an exponent is limited to +/- 15 digits.