Rounds a number to a specified number of significant figures.
Significant figures are digits that contribute to a number's precision. This function handles positive, negative, and small/large magnitude numbers.
The number to round.
The number of significant figures to retain (must be ≥ 1).
The rounded number with the specified significant figures.
sigFig(1234.567, 3); // 1230sigFig(0.012345, 2); // 0.012sigFig(-987.65, 2); // -990sigFig(0, 3); // 0 Copy
sigFig(1234.567, 3); // 1230sigFig(0.012345, 2); // 0.012sigFig(-987.65, 2); // -990sigFig(0, 3); // 0
Rounds a number to a specified number of significant figures.
Significant figures are digits that contribute to a number's precision. This function handles positive, negative, and small/large magnitude numbers.