有时候有些奇葩需要,一定要返回两位小数,可以使用下面方法
//保留两位小数,总投资
function changeTwoDecimal(f_x) {var s_x = f_x.toString();
var pos_decimal = s_x.indexOf('.');
if (pos_decimal < 0)
{
pos_decimal = s_x.length;
s_x += '.';
}
while (s_x.length <= pos_decimal + 2)
{
s_x += '0';
}
return s_x;
}
调用:changeTwoDecimal(data)
如:changeTwoDecimal(1.1)则返回1.10