Can be used as compareFn with Array.sort()
.
amount to compare with
0 if other is equal to this 1 if other should come before this when sorted -1 if other should come after this when sorted
Produces a new amount which is the quotient of this amount and the specified value (divisor), optionally specifying the number of decimals the end result should have.
the value to divide this amount with
Optional
decimals: number | "max"the number of decimals the end result should have, or "max" for
the highest value between this.decimals
and other.decimals
,
that is Math.max(this.decimals, other.decimals)
.
Defaults to this.decimals
new amount with the value "this amount" / "other amount"
Serializes this amount to its gtv
representation to be used when submitting it to the blockchain
Compares this amount with another value and returns true if this amount is equal to the other value
the value to compare
Compares this amount with another value and returns true if this amount is equal to the other value
the value to compare
Compares this amount with another value and returns true if this amount is greater than the other value
the value to compare
Compares this amount with another value and returns true if this amount is greater than or equal to the other value
the value to compare
Compares this amount with another value and returns true if this amount is lesser than the other value
the value to compare
Compares this amount with another value and returns true if this amount is lesser than or equal to the other value
the value to compare
Produces a new amount which is the difference of this amount and the specified value
the value to subtract
new amount with the value "this amount" - "other amount"
Produces a new amount which is the sum of this amount and the specified value
the value to add
new amount with the value "this amount" + "other amount"
Produces a new amount which is the product of this amount and the specified value, optionally specifying the number of decimals the end result should have.
the value to multiply this amount with
Optional
decimals: number | "max"the number of decimals the end result should have, or "max" for
the highest value between this.decimals
and other.decimals
,
that is Math.max(this.decimals, other.decimals)
.
Defaults to this.decimals
new amount with the value "this amount" * "other amount"
To be used if you want the precise value, down to the last digit. It must return a string, as a Number could still be overflowed and floating point numbers aren't precise in JS.
Optional
removeTrailingZeroes: booleanif true, trailing zeroes will be removed (0.800 -> 0.8). Defaults to true.
Returns the amount formatted as a readable string
the DecimalFormat to use
the number of digits to display
Optional
removeTrailingZeroes: booleanif true, trailing zeroes will be removed (0.800 -> 0.8)
The formatted string. WILL LOSE LOWER DIGIT PRECISION
scientific, 3-digits: 1.00e+18, 2.47e+3, 5.70e+0, 2.30e-4
fixed decimals, 3-digits: 13.750, 1987352342.435, 0.000, 12
mixed, 3-digits: 1.00e+18, 1.23e+3, 345, 12.0, 1.45e-1, 1.15e-2 !!NOT 0.01!!
returns the amount formatted as a readable string
the DecimalFormat to use
the number of digits to display
Optional
removeTrailingZeroes: booleanif true, trailing zeroes will be removed (0.800 -> 0.8)
Optional
groupDigits: booleanif true, when the format is not scientific, digits will be grouped by three (1234.5678 -> 1 234.567 8)
The formatted string. WILL LOSE LOWER DIGIT PRECISION
scientific, 3-digits: 1.00e+18, 2.47e+3, 5.70e+0, 2.30e-4
fixed decimals, 3-digits: 13.750, 1987352342.435, 0.000, 12
mixed, 3-digits: 1.00e+18, 1.23e+3, 345, 12.0, 1.45e-1, 1.15e-2 !!NOT 0.01!!
An amount consists of a value and number of decimals. It wraps a bigint value, and thus has the same limitations as a bigint in terms of size and precision.
The
Amount
interface also has methods to perform arithmetic operations on the amount with preserved precision.