How to round a number to 1 decimal place in TypeScript

2 Answers

0 votes
let num = 7.412897;
 
num = Number(num.toFixed(1));
 
console.log(num); 
 
    
    
    
    
/*
run:
    
7.4 
    
*/

 



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

 



answered Jun 18, 2022 by avibootz
...