用Javascript取float型小数点后两位,例
var a = 12.2369826取成12.23,如何做?下面四种方法可用
(1)
var str = a.substring(0,s.indexOf(".") + 3);
(2)
var n;
var re = /([0-9]+/.[0-9]{2})[0-9]*/;
n = a.replace(re,"$1");
(3)推荐
(Math.round(a*100)/100);
(4)
a.toFixed(2)