How to get the first two digits after the decimal point of a float number in Node.js

1 Answer

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

59
  
*/

 



answered Sep 18, 2024 by avibootz
...