View Single Post
Old 09-21-2012, 07:36 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
You are using grandTotal both as the name of an HTML element and a global Javascript variable. That will cause IE to barf.

Same with

var LHtotal;
var AHtotal;
var LMtotal;
var AMtotal;

But the big problem is

var orgTotal = orgTotal.toFixed(2);
grandTotal = Number(schoolTotal + orgTotal);

.toFixed() converts the numeric value to a string so the following + sign concatenates, not adds the values.

You should use toFixed() only to make a value for display purposes. It cannot be used for any subsequent mathematical calculation.

If you need to retain the value as a number use
Code:
<script type = "text/javascript">

function roundToDigits(number,digits) {
var p = Math.pow(10, digits);
return Math.round(number*p)/p;
}

alert (roundToDigits(123.456789,2));

</script>

Quizmaster: Do you know what 20 per cent of 100 is?
Contestant: 20 per cent of 100 is five per cent
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
greenhat (09-28-2012)