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 269 views
2 answers 281 views
2 answers 538 views
3 answers 320 views
3 answers 306 views
...