0

If the following function performs calculation

<script type="text/javascript">
function updatesum() {
document.PaymentForm.newbalance.value = (document.PaymentForm.balance.value -0) - (document.PaymentForm.paymentamount.value -0);
}
</script>

How do I incorporate above function and the one below into one to thus do the calculation and round the number?

<script type = "text/javascript">

function roundNumber(num, dec) {
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
return result;
}

alert (roundNumber (12345.6789, 2));
</script>

Any thoughts!
Mossa

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by mbarandao
0

If the following function performs calculation

<script type="text/javascript">
function updatesum() {
document.PaymentForm.newbalance.value = (document.PaymentForm.balance.value -0) - (document.PaymentForm.paymentamount.value -0);
}
</script>

How do I incorporate above function and the one below into one to thus do the calculation and round the number?

<script type = "text/javascript">

function roundNumber(num, dec) {
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
return result;
}

alert (roundNumber (12345.6789, 2));
</script>

Any thoughts!
Mossa

Found answer:

<script type="text/javascript">
function updatesum() {
var bal = document.PaymentForm.balance.value - document.PaymentForm.paymentamount.value;
bal = Math.round(bal*Math.pow(10,2))/Math.pow(10,2);
document.PaymentForm.newbalance.value = bal;
}
</script>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.