Plus operator in JavaScript doesn't sum my values

前端 未结 4 1745
深忆病人
深忆病人 2021-01-28 22:57

I\'m trying to calculate the number of payments but output was wrong so i tried to calculate a simple operation on the month value.But \"+\" operator doesn\'t sum my values it a

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-28 23:21

    Your input values are treated as string as they are textbox inputs. Parse the values first before adding them up.

    e.g.

    var principal = parseInt(princ.value); var interestrate = parseInt(interest.value);

提交回复
热议问题