0

In following case I want to round up the decimals. Please tell me how to do that. Now I am getting too many decimals. I wanted only 2 decimals...

<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>

Please help me out in this..

2 Answers2

2

You can use toFixed(2), eg

form.grandamount.value = form.grandamount.value.toFixed(2);
Evan Knowles
  • 7,426
  • 2
  • 37
  • 71
  • Hi sir, I just added the your code in the bottom of my script. I found no change in the output. Can you please help me out where I need to add. – Paresh Mithra Dec 09 '14 at 07:24
0

you can use JavaScript toFixed() Method to round decimal in javascript

var num = 5.56789;
var n = num.toFixed(2);
Nasir Mahmood
  • 1,445
  • 1
  • 13
  • 18