How to format number to always show 2 decimal places in JavaScript

4 Answers

0 votes
const num = 1

console.log(num.toFixed(2));
 
 
 
   
     
 
/*
run:
     
"1.00"
     
*/

 



answered Aug 4, 2021 by avibootz
0 votes
const num = 1.3489

console.log(num.toFixed(2));
 
 
 
   
     
 
/*
run:
     
"1.35"
     
*/

 



answered Aug 4, 2021 by avibootz
0 votes
const num = 1.3452

console.log(num.toFixed(2));
 
 
 
   
     
 
/*
run:
     
"1.35"
     
*/

 



answered Aug 4, 2021 by avibootz
0 votes
const num = 1.3441

console.log(num.toFixed(2));
 
 
 
   
     
 
/*
run:
     
"1.34"
     
*/

 



answered Aug 4, 2021 by avibootz

Related questions

2 answers 263 views
1 answer 279 views
2 answers 288 views
2 answers 253 views
1 answer 212 views
1 answer 265 views
...