// 参数:f ,待处理的数据;size,保留位数(4位以内)
function formatFloatToString(f, size) {
var af = f.toString().split(".");
//若为整数,直接补齐小数位为0
if (af.length == 1) {
return f + (".00000").substr(0, size + 1);
}
//若小数位小于、等于要保留的位数,补齐小数位为0
if (af[1].length <= size) {
return af[0] + "." + (af[1] + "00000").substr(0, size);
} else { debugger
//小数位大于要保留的位数
var lPart = af[0];
var rPart = af[1].substr(0, size);
var returnNum = lPart + "." + rPart;
//四舍五入
if (af[1].substr(size, 1) > 4) {
var addNum = ("0.00000").substr(0, size + 1) + "1";
var returnNum = parseFloat(returnNum) + parseFloat(addNum);
}
return returnNum;
}
}