How to convert float to string in JavaScript

2 Answers

0 votes
const f = 124.87619;
 
const s = f.toString();
 
console.log(s);

   
    
/*
run:
     
124.87619
        
*/

 



answered Aug 31, 2019 by avibootz
edited May 11, 2024 by avibootz
0 votes
const f = 123.964;
 
console.log(f.toFixed(1)); 
console.log(f.toFixed(2)); 
console.log(f.toFixed(3)); 
 
console.log(f.toString()); 

   
   
   
/*
run:
   
124.0
123.96
123.964
123.964
   
*/

 



answered May 11, 2024 by avibootz

Related questions

...