How to round a number to 3 decimal places in TypeScript

2 Answers

0 votes
let num = 7.351298;
 
num = Number(num.toFixed(3));
 
console.log(num); 
 
    
    
    
    
/*
run:
    
7.351 
    
*/

 



answered Jun 18, 2022 by avibootz
0 votes
let num = 7.452897;
 
num = Number(num.toFixed(3));
 
console.log(num); 
 
    
    
    
    
/*
run:
    
7.453 
    
*/

 



answered Jun 18, 2022 by avibootz

Related questions

4 answers 235 views
2 answers 149 views
2 answers 192 views
3 answers 325 views
2 answers 162 views
2 answers 152 views
...