big-amount
    Preparing search index...

    Variable qConst

    q: (x: BigAmountLike, y?: BigAmountLike) => BigAmount = BigAmount.create

    Creates a BigAmount from various arguments. This is a synonym for BigAmount.create.

    Type Declaration

      • (x: BigAmountLike, y?: BigAmountLike): BigAmount
      • Creates a BigAmount from various arguments. For convenience, this method is also exported as q and is callable as q(x) and q(x, y).

        Parameters

        • x: BigAmountLike

          bigint | number | string | { num: bigint | number | string; den: bigint | number | string }

        • Optionaly: BigAmountLike

          bigint | number | string | { num: bigint | number | string; den: bigint | number | string }

        Returns BigAmount

        q(123n);        // 123/1
        q(123); // 123/1
        q("123"); // 123/1
        q("123.45"); // 12345/100
        q("123.45e-6"); // 12345/100000000

        q("123/45"); // 123/45
        q("12.3/-4.5"); // 1230/-450

        Note that non-integral number values have to be passed as string.

        q(123.45);   // ERROR!
        q(123 / 45); // ERROR!
        q(123n, 45n);    // 123/45
        q(123, 45); // 123/45

        q(123, 45n); // 123/45
        q(123n, "4.5"); // 1230/45

        q("1/2", "3/4"); // 4/6
        q("1/2", "3.4"); // 10/68

        This method accepts the following BigAmount-like arguments:

        • bigint - Any bigint value.
        • number - Integer only. This is because it is often imprecise and expensive to find a rational approximate of a non-integral number. Pass the number as a string (e.g. "1/3", "1.23") to create an exact value or use BigAmount.fromNumber to find an approximate.
        • string - Fraction ("1/23"), integer ("123", "0xFF"), decimal ("-1.23", ".123"), or scientific ("1.23e-4", "-12e+3"). The fractional notation q("num/den") is equivalent to q("num", "den").
        • object - Any object (including any BigAmount value) that has two BigAmount-like scalar fields named num and den. q({ num: x, den: y }) is equivalent to q(x, y), except that the fields do not accept an object.