js截取小数点后几位的写法

  如果${showInfo.tt}的值为20,要要它除以10以后精确到小数点后2位,那么js代码中可作如下写法:

  

复制代码 代码如下:

  var a = ${showInfo.tt}/10;

  //alert(a.toFixed(3)); //表示到小数点后3位得出的值为2.000

  document.write(a.toFixed(2)); //得出的值为2.00