Class Big

The Big class for working with large numbers and fractions using BigInt.

Example

const big1 = new Big(123.456);
console.log(big1.toString()); // 123.456
const big2 = new Big("123.456");
console.log(big2.toString()); // 123.456
const big3 = new Big(123456n, 2);
console.log(big3.toString()); // 1234.56
const big4 = new Big(123.456, 2);
console.log(big4.toString()); // 1.23, because the scale is 2 and it removes the fractional part

Hierarchy

  • Big

Constructors

Properties

Methods

Constructors

  • Creates a new Big instance.

    Parameters

    • value: BigObject | Big

      The value to create the Big instance from.

    Returns Big

    • A new Big instance.

    Throws

    • If the value is not a number, string, BigInt, or Big instance.
  • Creates a new Big instance.

    Parameters

    • value: PossibleNumber

      The value to create the Big instance from. It Can be a number, string, or BigInt.

    Returns Big

    • A new Big instance.

    Throws

    • If the value is not a number, string, BigInt, or Big instance.
  • Creates a new Big instance.

    Parameters

    • value: PossibleNumber

      The value to create the Big instance from. Can be a number, string, or BigInt.

    • Optional scale: string | number

      The scale for the value (optional), representing the number of decimal places. If scale provided and value has a fractional part, the fractional part will be removed.

    Returns Big

    • A new Big instance.

    Throws

    • If the value is not a number, string, BigInt, or Big instance.

Properties

scale: number

The scale of the Big instance, representing the number of decimal places.

value: bigint

The value of the Big instance.

Methods

  • Returns the JSON representation of the Big instance.

    Returns string

    The JSON representation of the Big instance. It is the same as the string representation, because JSON does not support BigInt.

  • Returns a string representation of the Big instance.

    Parameters

    • Optional shouldTrimZeros: boolean = true

      Whether to trim trailing zeros from the fractional part. Defaults to true.

    Returns string

    • A string representation of the Big instance.
  • Returns the primitive value of the Big instance.

    Returns bigint

    The primitive value of the Big instance.

Generated using TypeDoc