Jump to content

Doing calculations in javascript.


eva21

Recommended Posts

Im having a hard time getting it to do the right calculations. Here is my javascript code:

 

//Checks to see if all the values have been inputted

  total = cost2 + travelCost2;

  cents = salary2/1920 * 76.5;

  dec = accCost2 * nightsAcc2;

  total2 = total + cents + dec;

  //total2 = total2.toFixed(2);

 

 

  //put it back into the total

  document.getElementById("totalCost").value = "$" + total2;

 

Except in the total box, it gives me total, cents, and dec into a string like for example

Total | 10.000.420

 

Why is it doing that instead of adding the three things together?

Link to comment
https://forums.phpfreaks.com/topic/135161-doing-calculations-in-javascript/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.