在下面的情况中,我想要舍入小数。请告诉我该怎么做。现在我得到了太多的小数。我只想要2位小数......
<SCRIPT LANGUAGE="LiveScript">
var a=0,b=0,c=0,d=0,e=0,f=0;
function grandtotalall(form){
form.weight8mm.value = form.rods8mm.value * 4.482;
form.amount8mm.value = form.weight8mm.value * 47.7;
a = form.weight8mm.value * 47.7;
form.weight10mm.value = form.rods10mm.value * 6.984;
form.amount10mm.value = form.weight10mm.value * 47.7;
b = form.weight10mm.value * 47.7;
form.weight12mm.value = form.rods12mm.value * 10.254;
form.amount12mm.value = form.weight12mm.value * 47.7;
c = form.weight12mm.value * 47.7;
form.weight16mm.value = form.rods16mm.value * 18.234;
form.amount16mm.value = form.weight16mm.value * 47.7;
d = form.weight16mm.value * 47.7;
form.weight20mm.value = form.rods20mm.value * 28.932;
form.amount20mm.value = form.weight20mm.value * 47.7;
e = form.weight20mm.value * 47.7;
form.weight25mm.value = form.rods25mm.value * 45.888;
form.amount25mm.value = form.weight25mm.value * 47.7;
f = form.weight25mm.value * 47.7;
form.grandamount.value = a + b + c + d + e + f;
}
</SCRIPT>
请帮帮我..
答案 0 :(得分:2)
您可以使用toFixed(2)
,例如
form.grandamount.value = form.grandamount.value.toFixed(2);
答案 1 :(得分:0)
您可以使用JavaScript toFixed() Method在javascript
中舍入小数var num = 5.56789;
var n = num.toFixed(2);