• Safely performs division with a specified decimal precision using Big numbers

    Parameters

    • value: Big

      The dividend (number to be divided)

    • dividend: BigSource

      The divisor (number to divide by)

    • decimals: number = 20

      The number of decimal places to maintain in the result (default: 20)

    Returns Big

    The result of the division with the specified precision

    const value = new Big('10');
    const result = safeDiv(value, 3); // Returns Big('3.33333...') with 20 decimals
    const precise = safeDiv(value, 3, 5); // Returns Big('3.33333') with 5 decimals
    • Temporarily modifies the global decimal precision (Big.DP) to perform the division
    • Restores the original precision after calculation
    • Ensures accurate division results without affecting other calculations
    • Useful for operations requiring specific precision like financial calculations
    • Default precision of 20 decimals is suitable for most use cases