Use Javascript to get the two decimal places after the float type. For example, 22.127456 is changed to 22.13. How to do it?
1. The stupidest way
function get()
{
var s = 22.127456 "";
var str = s.substring(0,s.indexOf(".") 3);
alert(str ; >
The code is as follows:
3. He is smarter
.....
Copy code
The code is as follows:
<script> <strong>var num=22.127456; </strong> alert( Math.round(num*100)/100); <br></script>
Copy code
The code is as follows:
<script> <strong>var num=22.127456; </strong>alert( num.toFixed(2)); <br></script>