CurrencyAmount
Enables the safe handling of currency amounts.
GitHub File: currencyAmount.ts
Extends
Properties
Public
Property | Type | Modifier | Description |
---|---|---|---|
currency | T | readonly | The currency amount. |
decimalScale | readonly | Number of decimals for the currency. |
Constructor - protected
protected
Generics Type Definitions
Generics Name | Description |
---|---|
T | Extends |
Parameters
Params | Type | Description |
---|---|---|
currency | T | The currency. |
numerator | The numerator currency amount to be created. | |
denominator | The denominator currency amount to be created. Optional. |
Methods
fromRawAmount() - public
static
public
static
Returns a new currency amount instance from the unitless amount of token (i.e. the raw amount).
Parameters
Returns
Type | Description |
---|---|
CurrencyAmount<T> | The amount of currency in the specified currency amount format. |
fromFractionalAmount() - public
static
public
static
Returns a new currency amount instance with a denominator that is not equal to 1.
Parameters
Params | Type | Description |
---|---|---|
currency | T | The currency. |
numerator | The numerator of the fractional token amount. | |
denominator | The denominator of the fractional token amount. |
Returns
Type | Description |
---|---|
CurrencyAmount<T> | The amount of currency in the specified currency amount format. |
add() - public
public
Adds the provided currencyAmount to the CurrencyAmount instance and returns the result as a new currencyAmount.
Parameters
Params | Type | Description |
---|---|---|
other | CurrencyAmount<T> | The currencyAmount to be added to the CurrencyAmount instance. |
Returns
Type | Description |
---|---|
CurrencyAmount<T> | The currencyAmount representing the sum of the two currencyAmounts. |
subtract() - public
public
Subtracts/minuses the provided currencyAmount from the CurrencyAmount instance and returns the result as a new currencyAmount.
Parameters
Params | Type | Description |
---|---|---|
other | CurrencyAmount<T> | The currencyAmount to be subtracted from the CurrencyAmount instance. |
Returns
Type | Description |
---|---|
CurrencyAmount<T> | The final currencyAmount after subtracting the given currencyAmount from the CurrencyAmount instance. |
multiply() - public
public
Multiplies the CurrencyAmount instance with the provided currencyAmount and returns the result as a new currencyAmount.
Parameters
Params | Type | Description |
---|---|---|
other | CurrencyAmount<T> | The currencyAmount to be multiplied with the CurrencyAmount instance. |
Returns
Type | Description |
---|---|
CurrencyAmount<T> | The final currencyAmount after multiplying the given currencyAmount with the CurrencyAmount instance. |
divide() - public
public
Divides the currencyAmount instance with the provided currencyAmount and returns the result as a new currencyAmount.
Parameters
Params | Type | Description |
---|---|---|
other | CurrencyAmount<T> | The currencyAmount to be divided from the CurrencyAmount instance. |
Returns
Type | Description |
---|---|
CurrencyAmount<T> | The final currencyAmount after dividing the CurrencyAmount instance by the provided currencyAmount. |
toSignificant() - public
public
Rounds the CurrencyAmount instance to the significant digits specified.
Parameters
Params | Type | Description |
---|---|---|
significantDigits | number | The number of significant digits to round to. Default is |
format | object | Configure output format per toformat specifications. |
rounding | Specifies the rounding logic used. Default is |
Returns
Type | Description |
---|---|
string | The final quotient value rounded to the specified significant digits. |
toFixed() - public
public
Rounds the currencyAmount instance to the fixed number of decimals specified.
Parameters
Params | Type | Description |
---|---|---|
decimalPlaces | number | The number of decimal places to round to. Default is the currency's decimal places. |
format | object | Configure output format per toformat specifications. |
rounding | Specifies the rounding logic used. Default is |
Returns
Type | Description |
---|---|
string | The final quotient value rounded to the decimal places specified. |
toExact() - public
public
Gets the exact CurrencyAmount instance value with the default currency decimals.
Parameters
Params | Type | Description |
---|---|---|
format | object | Configure output format per toformat specifications. |
Returns
Type | Description |
---|---|
string | The final exact quotient value down to the currency's default decimals. |
wrapped() - public
get
public
get
Returns the wrapped version of the currencyAmount instance after accounting for whether the currency is a Token or NativeCurrency.
Returns
Type | Description |
---|---|
Token | The wrapped version of the currencyAmount instance. |
Last updated