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

2 answers 111 views
2 answers 142 views
3 answers 254 views
2 answers 127 views
2 answers 107 views
...