stan801003

01-05-2011, 08:57 AM

Hi,

I have a piece of code to calculate the vat on a product form i use, which works fine, the problem is now the vat has increased i am not sure how to increase the code to change the vat from 17.5 % to 20 %.

And would be grateful if somebody could point me in the right direction.

Thanks

Stan

//Calculate VAT

function pound(num) {

var i,l,d;

var nums;

var ret;

nums = String(Math.round(num*100));

while (nums.length <3) nums = "0" + nums;

l = nums.length-3;

ret = "." + nums.charAt(l+1) + nums.charAt(l+2);

d=0;

for (i=l; i>=0; i--) {

ret = nums.charAt(i) + ret;

d++;

if (d==3 && i>0) {

ret="," + ret;

d=0;

}

}

ret = "£" + ret;

return ret;

}

// this is the calculation function

function calcVat(form, field, field2, field3, vat) {

var amount = eval(document[form][field].value);

var sum = amount*vat;

var total = pound(amount+sum);

document[form][field2].value=total;

document[form][field3].value=pound(sum);

return false;

}

I have a piece of code to calculate the vat on a product form i use, which works fine, the problem is now the vat has increased i am not sure how to increase the code to change the vat from 17.5 % to 20 %.

And would be grateful if somebody could point me in the right direction.

Thanks

Stan

//Calculate VAT

function pound(num) {

var i,l,d;

var nums;

var ret;

nums = String(Math.round(num*100));

while (nums.length <3) nums = "0" + nums;

l = nums.length-3;

ret = "." + nums.charAt(l+1) + nums.charAt(l+2);

d=0;

for (i=l; i>=0; i--) {

ret = nums.charAt(i) + ret;

d++;

if (d==3 && i>0) {

ret="," + ret;

d=0;

}

}

ret = "£" + ret;

return ret;

}

// this is the calculation function

function calcVat(form, field, field2, field3, vat) {

var amount = eval(document[form][field].value);

var sum = amount*vat;

var total = pound(amount+sum);

document[form][field2].value=total;

document[form][field3].value=pound(sum);

return false;

}