JavaScript RangeError Precision is out of range

This JavaScript exception precision is out of range occurs if a number that is outside the range of 0 and 20 (or 21) is passed into toFixed(), toPrecision(), or toExponential() method.
Error Message:
RangeError: The number of fractional digits is out of range (Edge)
RangeError: The precision is out of range (Edge)
RangeError: precision {0} out of range (Firefox)
RangeError: toExponential() argument must be between 0 and 20 (Chrome)
RangeError: toFixed() digits argument must be between 0 and 20 (Chrome)
RangeError: toPrecision() argument must be between 1 and 21 (Chrome)
Error Type:
RangeError
What Happened?
There is a precision argument that is out of range in one of the methods, toExponential(), toFixed(), and toPrecision().
Example 1: In this example, the RangeError occurred as -100 to toFixed() is passed.
Javascript
function Geeks() {Â Â Â Â try {Â Â Â Â Â Â Â Â 3.54.toFixed(-100);Â
        console.log("'Precision out of range'"            + " error has not occurred");    } catch (e) {        console.log("'Precision out of range'"            + " error has occurred");    }}Â
Geeks(); |
Output:
'Precision out of range' error has occurred
Example 2: In this example, the argument passed to toExponential() is -4, So the RangeError has occurred.
Javascript
function Geeks() {Â Â Â Â try {Â Â Â Â Â Â Â Â 77.1234.toExponential(-4);Â
        console.log("'Precision out of range'"            + " error has not occurred");    } catch (e) {        console.log("'Precision out of range'"            + " error has occurred");    }} Â
Geeks(); |
Output:
'Precision out of range' error has occurred
Example 3: In this example, the RangeError occurred as -1 to toPrecision() is passed.
Javascript
function Geeks() {Â Â Â Â try {Â Â Â Â Â Â Â Â 5643.9.toPrecision(-1);Â
        console.log("'Precision out of range'"            + " error has not occurred");    } catch (e) {        console.log("'Precision out of range'"            + " error has occurred");    }} Â
Geeks(); |
Output:
'Precision out of range' error has occurred
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!



