Powered by Blogger.

Round Number Into 2 Decimal in JavaScript


There is the custom function to round 2 decimal number in JavaScript

 function financial(x) {  
 return Number.parseFloat(x).toFixed(2);  
 }  
 console.log(financial(12.786));  
 // expected output: "12.79"  
 console.log(financial(0.0078));  
 // expected output: "0.01"  
 console.log(financial('1.25e+5  
 // expected output: "125000.00"  

No comments