Friday, September 5, 2025
HomeLanguagesJavascriptJavaScript RangeError Precision is out of range

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, neveropen 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!
RELATED ARTICLES

Most Popular

Dominic
32265 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS