How to parse float with 2 decimal places in JavaScript

2 Answers

0 votes
let f = 4.1936;

f = parseFloat(f).toFixed(2);

console.log(f); 


  
  
  
/*
run:
  
"4.19"
  
*/

 



answered Jun 19, 2022 by avibootz
0 votes
let f = 4.1987;

f = parseFloat(f).toFixed(2);

console.log(f); 


  
  
  
/*
run:
  
"4.20"
  
*/

 



answered Jun 19, 2022 by avibootz

Related questions

2 answers 145 views
2 answers 163 views
2 answers 404 views
3 answers 150 views
3 answers 141 views
...