Class: BigNumber
moralis-monorepo / @moralisweb3/common-core / BigNumber
Class: BigNumber
@moralisweb3/common-core.BigNumber
The BigNumber class is a MoralisData that references to a the value of a BigNumber
Table of contents
Methods
Methods
create
▸ Static
create(value
): BigNumber
Create a new instance of BigNumber from any valid address input.
Example
BigNumber.create(12);
Example
BigNumber.create("20");
Parameters
Name | Type | Description |
---|---|---|
value | BigNumberInput | the BigNumberish type |
Returns
a new BigNumber instance
fromDecimal
▸ Static
fromDecimal(value
, decimals?
): BigNumber
Creates a new BigNumber from given decimals.
Example
BigNumber.fromDecimal("1.23456789", 18);
Parameters
Name | Type | Default value | Description |
---|---|---|---|
value | BigNumberPrimitive | undefined | |
decimals | number | 0 | This is optional and defaults to 0 |
Returns
fromJSON
▸ Static
fromJSON(json
): BigNumber
Parameters
Name | Type |
---|---|
json | string |
Returns
add
▸ add(value
): BigNumber
Adds a BigNumber to current BigNumber instance.
Example
BigNumber.create(12).add(7);
Example
BigNumber.create(12).add("1000000000000000000");
Parameters
Name | Type | Description |
---|---|---|
value | BigNumberInput | the BigNumberish to add |
Returns
the result of the addition
div
▸ div(value
): BigNumber
Divides a BigNumber with current BigNumber instance.
Example
BigNumber.create(12).div(7);
Example
BigNumber.create(1).div("1000000000000000000");
Parameters
Name | Type | Description |
---|---|---|
value | BigNumberInput | the BigNumberish to divide |
Returns
the result of the division
equals
▸ equals(value
): boolean
Checks the equality of the current BigNumber with another BigNumber.
Example
BigNumber.create(12).equals(BigNumber.create(12)); // true
Parameters
Name | Type | Description |
---|---|---|
value | BigNumber | the BigNumberish to compare |
Returns
boolean
true if the BigNumbers are equal
mul
▸ mul(value
): BigNumber
Multiplies a BigNumber with current BigNumber instance.
Example
BigNumber.create(12).mul(7);
Example
BigNumber.create(12).mul("1000000000000000000");
Parameters
Name | Type | Description |
---|---|---|
value | BigNumberInput | the BigNumberish to multiply |
Returns
the result of the multiplication
sub
▸ sub(value
): BigNumber
Subtracts a BigNumber from current BigNumber instance.
Example
BigNumber.create(12).sub(7);
Example
BigNumber.create("1000000000000000000").sub(20);
Parameters
Name | Type | Description |
---|---|---|
value | BigNumberInput | the BigNumberish to subtract |
Returns
the result of the subtraction
toBigInt
▸ toBigInt(): bigint
Example
BigNumber.create(12).toBigInt();
Returns
bigint
the value of this BigNumber as a BigInt
toDecimal
▸ toDecimal(decimals
): string
Converts BigNumber instance to value in given decimals.
Example
BigNumber.create(12).toDecimal(18);
Parameters
Name | Type | Description |
---|---|---|
decimals | number | The decimals to convert to |
Returns
string
toHex
▸ toHex(): string
Converts BigNumber instance to hex string.
Example
BigNumber.create(12).toHex();
Returns
string
toJSON
▸ toJSON(): string
Converts BigNumber instance to hex string.
Example
BigNumber.create(12).toJSON();
Returns
string
toString
▸ toString(): string
Converts BigNumber instance to string.
Example
BigNumber.create(12).toString();
Returns
string