Piotto

11-09-2009, 02:45 PM

Hi everybody!

I am trying to add a rounding function inside the multiplication function Vic helped me to assemble. But is not working... I mean the multiplication works but the rounding not.

What i need is to round the multiplication results to 2 decimal even if the number is integer (like 100 i need to be 100.00).

The code....

[CODE]

<SCRIPT language = JavaScript>

<!--

function calculate2() {

var frm=document.catalogo1;

var a=frm.itemprice;

var b=frm.itemquantity;

var c=frm.subtotal;

for (var z0=0;z0<a.length;z0++){

c[z0].value=a[z0].value*b[z0].value;

//below here is not working

var newnumber = Math.round(c[z0].value*Math.pow(10,2))/Math.pow(10,2);

document.catalogo1.subtotal.value = newnumber;

}

}

//-->

</SCRIPT>

[CODE]

What i am doing wrong? :confused:

Alex Piotto

I am trying to add a rounding function inside the multiplication function Vic helped me to assemble. But is not working... I mean the multiplication works but the rounding not.

What i need is to round the multiplication results to 2 decimal even if the number is integer (like 100 i need to be 100.00).

The code....

[CODE]

<SCRIPT language = JavaScript>

<!--

function calculate2() {

var frm=document.catalogo1;

var a=frm.itemprice;

var b=frm.itemquantity;

var c=frm.subtotal;

for (var z0=0;z0<a.length;z0++){

c[z0].value=a[z0].value*b[z0].value;

//below here is not working

var newnumber = Math.round(c[z0].value*Math.pow(10,2))/Math.pow(10,2);

document.catalogo1.subtotal.value = newnumber;

}

}

//-->

</SCRIPT>

[CODE]

What i am doing wrong? :confused:

Alex Piotto