复制代码代码如下所示:
无功changetwodecimal_f =
功能(floatvar){
无功f_x = parseFloat(floatvar);
如果(isnan(f_x)){
返回'0.00;
}
无功f_x = math.round(f_x * 100)/ 100;
无功s_x = f_x.tostring();
无功pos_decimal = s_x.indexof(' ');
如果(pos_decimal<0){
pos_decimal = s_x.length;
s_x += '。;
}
而(s_x.length <= pos_decimal + 2){
s_x = '0';
}
返回s_x;
}
由JS提供的四宫五功能:
复制代码代码如下所示:
JS四家五功能
设置(),其中
参数的小数位数保留。
document.write(JS保留小数点后两实例);
var a=2.1512131231231321;
document.write(原始值:+ +);
document.write(两小数点:a.tofixed +(2)+四位小数点+ a.tofixed(4));