Function calcPercentage

  • Calculates the percentage of the given secondary value from the main value

    Parameters

    • value: string | number | bigint

      The main value

    • secondValue: string | number | bigint

      The secondary value

    • decimals: number

      The decimals of the value.

    • Optional precision: number

      The precision of the result. Default is 3.

    Returns number

    The percentage with the given precision

    Example

    calcPercentage('100', '10', 2) // 10
    calcPercentage(50, 75, 0) // 150
    calcPercentage(BigInt(125e9), '62500000000', 9) // 50
    calcPercentage('1234567898765432123456789', '617283949382716061728394', 18) // 50