Creates a new CurrencyAmount instance.
The raw amount as a bigint (in smallest units)
The number of decimal places for this currency
Adds another CurrencyAmount to this one. Both amounts must have the same number of decimals.
The other CurrencyAmount to add
A new CurrencyAmount with the sum
Gets the raw amount as a bigint value. This represents the amount in the smallest unit (e.g., wei for ETH, satoshis for BTC).
The raw amount as a bigint
Compares this CurrencyAmount with another.
The other CurrencyAmount to compare
-1 if this < other, 0 if equal, 1 if this > other
Gets the number of decimal places for this currency.
The number of decimal places
Divides this CurrencyAmount by a number.
The number to divide by
A new CurrencyAmount with the quotient
Checks if this CurrencyAmount equals another.
The other CurrencyAmount to compare
True if equal, false otherwise
Checks if this CurrencyAmount is greater than another.
The other CurrencyAmount to compare
True if this > other, false otherwise
Checks if this CurrencyAmount is negative.
True if the amount is negative, false otherwise
Checks if this CurrencyAmount is positive.
True if the amount is positive, false otherwise
Checks if this CurrencyAmount is zero.
True if the amount is zero, false otherwise
Checks if this CurrencyAmount is less than another.
The other CurrencyAmount to compare
True if this < other, false otherwise
Multiplies this CurrencyAmount by a number.
The number to multiply by
A new CurrencyAmount with the product
Subtracts another CurrencyAmount from this one. Both amounts must have the same number of decimals.
The other CurrencyAmount to subtract
A new CurrencyAmount with the difference
Formats the currency amount using abbreviated notation (K, M, B, T). Examples: 1,500 -> "1.5K", 2,500,000 -> "2.5M", 1,000,000,000 -> "1B"
Optional number of decimal places for the abbreviated value (default: 1)
Formatted string with K/M/B/T suffix
Formats the currency amount to a string with a specified number of decimal places.
The number of decimal places to display
Formatted string with the specified decimal places
Converts the currency amount to a JavaScript number. Note: This may lose precision for very large amounts.
The amount as a number
Converts the currency amount to a string representation.
String representation of the amount
Static
fromCreates a CurrencyAmount from a decimal string or number.
The decimal value as a string or number
A new CurrencyAmount instance
Concrete implementation of ICurrencyAmount for handling currency amounts with precise decimal arithmetic.