Sunday, January 18, 2026
HomeLanguagesJavascriptTypeScript | toPrecision() Function

TypeScript | toPrecision() Function

The toPrecision() method in TypeScript is used to return the string representation in exponential or fixed-point to the specified precision.

Syntax:

number.toPrecision( [ precision ] )

Parameter: It represents an integer value specifying the number of significant digits.

Return Value: The toPrecision() method in TypeScript returns a string representing a Number in fixed-point or exponential notation round to precision significant digits.

Below examples illustrate the working of toPrecision() function in TypeScript:

Example 1:




<script>
  
// toPrecision() method
var num = new Number(6.218956); 
console.log(num.toPrecision()); 
console.log(num.toPrecision(4)); 
console.log(num.toPrecision(3));
</script>


Output:

6.218956 
6.2189 
6.21

Example 2:




<script>
  
// toPrecision() method
let myNumber: number = 32.5779; 
console.log("Number Method: toPrecision()");  
console.log(myNumber.toPrecision(1));   
console.log(myNumber.toPrecision(3));  
</script>


Output:

Number Method: toPrecision()
3e+1
32.6
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
32474 POSTS0 COMMENTS
Milvus
118 POSTS0 COMMENTS
Nango Kala
6846 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12063 POSTS0 COMMENTS
Shaida Kate Naidoo
6985 POSTS0 COMMENTS
Ted Musemwa
7219 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6911 POSTS0 COMMENTS