
I found this class in @dfinity/nns npm package:
/**
* Represents an amount of tokens.
*
* @param e8s - The amount of tokens in bigint.
* @param token - The token type.
*/
export declare class TokenAmount {
protected e8s: bigint;
token: Token;
private constructor();
/**
* Initialize from a bigint. Bigint are considered e8s.
*
* @param {amount: bigint; token?: Token;} params
* @param {bigint} params.amount The amount in bigint format.
* @param {Token} params.token The token type.
*/
static fromE8s({ amount, token, }: {
amount: bigint;
token: Token;
}): TokenAmount;
/**
* Initialize from a string. Accepted formats:
*
* 1234567.8901
* 1'234'567.8901
* 1,234,567.8901
*
* @param {amount: string; token?: Token;} params
* @param {string} params.amount The amount in string format.
* @param {Token} params.token The token type.
*/
static fromString({ amount, token, }: {
amount: string;
token: Token;
}): TokenAmount | FromStringToTokenError;
/**
* Initialize from a number.
*
* 1 integer is considered E8S_PER_TOKEN
*
* @param {amount: number; token?: Token;} params
* @param {string} params.amount The amount in number format.
* @param {Token} params.token The token type.
*/
static fromNumber({ amount, token, }: {
amount: number;
token: Token;
}): TokenAmount;
/**
*
* @returns The amount of e8s.
*/
toE8s(): bigint;
/**
* TODO: Remove this method when ICP class is not used anymore
* @deprecated
*/
toProto(): Promise<ICPTs>;
}
How to handle decimals of e8s of ICP token?