SheetXL - v0.3.20
    Preparing search index...
    • 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 movable-point precision errors commonly associated with rounding in JavaScript.

      Parameters

      • number: number

        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

      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