Skip to main content

toNumber

Callable

  • toNumber(value: Numbers): number | bigint

  • Converts any given value into it's number representation, if possible, else into it's bigint representation.

    @example
    console.log(web3.utils.toNumber(1));
    > 1
    console.log(web3.utils.toNumber(Number.MAX_SAFE_INTEGER));
    > 9007199254740991

    console.log(web3.utils.toNumber(BigInt(Number.MAX_SAFE_INTEGER)));
    > 9007199254740991

    console.log(web3.utils.toNumber(BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1)));
    > 9007199254740992n

    Parameters

    Returns number | bigint

    • Returns the value in number or bigint representation