Possible Duplicate:
JavaScript: formatting number with exactly two decimals
Round up to 2 decimal places in javascript
<form name="shippingForm" method="post" action="">
<h2>Product Cost</h2>
<ul>
<li><input type="text" name="YourValue" id="YourValue" value=""/></li>
<li><label>VAT @ 17.5% +</label></li>
<li><input type="text" name="costShipping" id="costShipping" value=""/></li>
<li><label>Currency conversion rate: 1.98</label></li>
<li><div id="totalPrice"></div></li>
<li><input type="button" value="Calculate" name="calculate" id="calculate"/></li>
</ul>
</form>
Above is the form. What this does, is ask the user to enter 2 values, but the 2nd value is optional. It then calculates and displays the result.
<script type="text/javascript">
var button = document.getElementById('calculate');
button.onclick = function() {
var YourValue = parseInt(document.getElementById('YourValue').value);
var LocalTax = 17.5/100 * YourValue;
var costShipping = parseInt(document.getElementById('costShipping').value);
var convCurrency = 1.98;
var totalPrice = document.getElementById('totalPrice');
if (document.getElementById('costShipping').value === "") {
totalPrice.innerHTML = "= $"+(YourValue + LocalTax + 0) * convCurrency;
}
else {
totalPrice.innerHTML = "= $"+(YourValue + LocalTax + costShipping) * convCurrency;
}
};
</script>
what i would like to do is to round off the totalPrice result to 2 decimals