Search code examples
javascriptjqueryfloating-pointinteger

How to add integer and float using javascript?


I am using the below code to add integer and float value using JavaScript. But I can't do this, it returns NaN. I am new to development. Please help me to solve this.

lbl_bal_total.value = Numbers(lbl_bal_total.innerHTML) + Numbers(lbl_bal_others.value);
//lbl_bal_total.value = 1568 + .25; // Error lbl_bal_total value is NaN
lbl_bal_total.innerHTML = Math.round(lbl_bal_total.value);

Solution

  • Try this:

    lbl_bal_total.innerHTML = Math.round(parseFloat(lbl_bal_total.innerHTML) + parseFloat(lbl_bal_others.value));