javascript (+) sign concatenates instead of giving sum?

后端 未结 7 525
旧巷少年郎
旧巷少年郎 2020-12-07 03:41

I created a simple program that make the sum of two numbers BUT.. the program is concatenating instead, This is so confusing! Can anyone help?

7条回答
  •  悲哀的现实
    2020-12-07 04:30

    It's just because value returns with string. So sum operation ends with concatenation. you need to convert both those values.

    user below code

     var sum = parseFloat(numberOne) + parseFloat(numberTwo);
    

提交回复
热议问题