@jossmac/lil-libs
    Preparing search index...

    Function roundToPrecision

    • Rounds a number to a fixed number of decimal places.

      Rounds by the decimal value as written, so 1.005 rounds to 1.01 even though its binary representation is slightly below 1.005. Halfway values round away from zero. When digits <= 0, rounds to the nearest integer. The base parameter defaults to 10; most callers should leave it unchanged.

      • value: number

        Number to round.

      • digits: number

        Fractional digits to keep; values <= 0 round to the nearest integer.

      • base: number = 10

        Radix used for scaling (default 10); most callers should leave this unchanged.

      value rounded to digits decimal places at the given base; values that already fit within digits are returned unchanged.

      roundToPrecision(3.14159, 2); // 3.14
      roundToPrecision(1.005, 2); // 1.01
      roundToPrecision(-2.5, 0); // -3
      roundToPrecision(3.7, 0); // 4