This article mainly introduces the js amount processing plus two decimal places, which has a certain reference value. Now I share it with everyone. Friends in need can refer to it
function toDecimal2(x) { var f = parseFloat(x); if (isNaN(f)) { return false; } var f = Math.round(x*100)/100; var s = f.toString(); var rs = s.indexOf('.'); if (rs < 0) { rs = s.length; s += '.'; } while (s.length <= rs + 2) { s += '0'; } return s; }
The above is the entire content of this article , I hope it will be helpful to everyone’s learning. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
js time and millisecond conversion
js moves any element to the specified position
About the implementation of JS effect function
The above is the detailed content of js amount processing plus two decimal places. For more information, please follow other related articles on the PHP Chinese website!