simonpearce
ISP
Hi,
I'm trying to round to decimal places - this code works on the whole but if that answer is 14.1 I want it to show as 14.10
Any ideas?
Simon
<script language="javascript"><!--
function doRound(x, places) {
return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
}
function updateGross() {
var taxRate = 17.5;
var grossValue = document.forms["FORM"].Amount.value;
var vat;
grossValue = grossValue * ((taxRate / 100) + 1);
vat = doRound(grossValue, 2) - document.forms["FORM"].Amount.value;
document.forms["FORM"].TOTAL.value = doRound(grossValue, 2);
document.forms["FORM"].VAT.value = doRound(vat, 2);
}
//--></script>
I'm trying to round to decimal places - this code works on the whole but if that answer is 14.1 I want it to show as 14.10
Any ideas?
Simon
<script language="javascript"><!--
function doRound(x, places) {
return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
}
function updateGross() {
var taxRate = 17.5;
var grossValue = document.forms["FORM"].Amount.value;
var vat;
grossValue = grossValue * ((taxRate / 100) + 1);
vat = doRound(grossValue, 2) - document.forms["FORM"].Amount.value;
document.forms["FORM"].TOTAL.value = doRound(grossValue, 2);
document.forms["FORM"].VAT.value = doRound(vat, 2);
}
//--></script>