How to ensure javascript addition instead of string concatenation (Not always adding integers)

前端 未结 4 1346
野的像风
野的像风 2020-12-11 19:16

Through my javascript library, I end up with a string that represents a number. Now I want to preform an addition on that number without it doing a string concatenation inst

4条回答
  •  有刺的猬
    2020-12-11 19:38

    Try using parseFloat. The input variables will be converted to floats, which will work whether the string contains an integer or a float. Your result will always be a float.

提交回复
热议问题