I ahve set up some calculations using javascript code, but to my horror it displays way too many decimal places, how can i resrict the calculations result to 2 decimal places?
This is the snippet of code i am using!
The calculation is made up of a subtotal with the VAT being added onto it. Some results do only display 2 decimal places but more often than not it displays recuring decimal places!
Thanx in advance for any help!
This is the snippet of code i am using!
Code:
function dm(amount)
{
string = "" + amount;
dec = string.length - string.indexOf('.');
if (string.indexOf('.') == -1)
return string + '.00';
if (dec == 1)
return string + '00';
if (dec == 2)
return string + '0';
if (dec > 3)
return string.substring(0,string.length-dec+3);
return string;
}
Code:
incvat = vat + subtotal;
document.form1.incvat.value = dm(eval(incvat));
The calculation is made up of a subtotal with the VAT being added onto it. Some results do only display 2 decimal places but more often than not it displays recuring decimal places!
Thanx in advance for any help!