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

1 Answer

0 votes
const f: number = 13756.847021; 
   
const s: string = f.toString();
  
const point_pos: number = s.indexOf('.');
 
console.log(s.substring(point_pos + 1, point_pos + 1 + 2)); 
       
 
 
/*
run:

"84" 
  
*/

 



answered Sep 18, 2024 by avibootz
...