Use Javascript to take two decimal places after float type, and use example 22.127456 to 22.13. How to do it?
1. This method is the least recommended:
function get(){ var s = 22.127456 + ""; var str = s.substring(0,s.indexOf(".") + 3); alert(str); }2. Use regular expressions to get:
function get(){ var a = "23.456322"; var aNew; var re = /([0-9]+/.[0-9]{2})[0-9]*/; aNew = a.replace(re,"$1"); alert(aNew); }3. More advanced applications:
function get(){ var num=22.127456; alert( Math.round(num*100)/100); }4. The simplest and most convenient:
function get(){ var num = new Number(13.37); num = num.toFixed(2);//2 is the number of digits after the decimal to get, it will automatically round to alert(num); }