-1

In the below code im going to add two number but there not add just shows me two numbers respectively.

 var gross = $('#txtgross').val();// 226800.00
 tax = ((vat) + (nbt)); // vat is 34020.00 and nbt is 4536.00

 net = ((gross) + tax.toFixed(2)); // 226800.00 38556.00 <-- in here not calculated but it just shows the Gross & Total Tax (nbt + vat) amounts respectively
TechGuy
  • 4,298
  • 15
  • 56
  • 87

1 Answers1

1

Use parseInt to add numbers as shown :

var tax = (parseInt(vat) + parseInt(nbt)); 

or Use parseFloat as shown :

var tax = (parseFloat(vat) + parseFloat(nbt)); 

The problem in your case is that the numbers are also considered as strings and when you are adding them then the strings are just concatenating.

Kartikeya Khosla
  • 18,743
  • 8
  • 43
  • 69