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 216 views
2 answers 137 views
2 answers 185 views
3 answers 314 views
2 answers 156 views
2 answers 142 views
...