How to get the first digit after the decimal point of a float number in TypeScript

2 Answers

0 votes
const f = 895.98731;
   
console.log(f.toString().split('.')[1][0]); 
       
 
 
    
/*
run:
     
"9" 
        
*/

 



answered Jun 17, 2022 by avibootz
0 votes
const f = 895.98731;
   
console.log((Math.floor(Math.abs(f) * 10)) % 10); 
       
 
 
    
/*
run:
     
9
        
*/

 



answered Jun 17, 2022 by avibootz
...