How to get convert number to string with specific precision in TypeScript

1 Answer

0 votes
const num:number = 3.14159265359; 

console.log(num.toPrecision()); 
console.log(num.toPrecision(1)); 
console.log(num.toPrecision(2));
console.log(num.toPrecision(3));
 

 
 
/*
run:
  
"3.14159265359" 
"3" 
"3.1" 
"3.14" 
  
*/

 



answered Oct 26, 2021 by avibootz
...