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

1 Answer

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

 



answered Sep 1, 2019 by avibootz
edited Sep 18, 2024 by avibootz
...