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 247 views
2 answers 154 views
2 answers 196 views
3 answers 333 views
2 answers 164 views
2 answers 155 views
...