Function fromString

  • Convert a number or string to normal string number. Supports scientific notation.

    Type Parameters

    • Type extends boolean

    Parameters

    • num: string | number

      The number to convert

    • Optional ignoreFraction: boolean

      Whether to ignore the fractional part of the number. Defaults to false.

    • Optional returnInstance: Type

      Whether to return a Big instance or BigObject. Defaults to true.

    Returns Type extends true
        ? Big
        : BigObject

    • A Big instance or BigObject representing the number

    Throws

    • If the number is too big or too small

    Throws

    • If the number is invalid

    Example

    fromString("123.456"); // Big { value: 123456n, scale: 3 }
    fromString("123.456", true); // Big { value: 123n, scale: 0 }
    fromString("123.456", false, false); // { value: 123456n, scale: 3 }
    fromString("1.5e3"); // Big { value: 1500n, scale: 0 }

Generated using TypeDoc