SheetXL - v0.8.0-beta.9+sites.210.e2d420901
    Preparing search index...

    Function roundAccurately

    • Rounds a number to a specified number of decimal places, ensuring precision is maintained. If no decimal places are provided, the default is 0 (rounds to the nearest integer).

      This function uses scientific notation to avoid floating-point precision errors commonly associated with rounding in JavaScript.

      Parameters

      • number: number | null

        The number to round. If the number is null or not finite (e.g., Infinity), null is returned.

      • decimalPlaces: number = 0

        The number of decimal places to round to (default is 0).

      Returns number | null

      The rounded number, or null if the input is invalid.

      roundAccurately(123.4567, 2); // 123.46
      roundAccurately(123.4567); // 123
      roundAccurately(123.4567, 0); // 123
      roundAccurately(null); // null
      roundAccurately(Infinity); // null