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

前端 未结 4 1367
野的像风
野的像风 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:49

    It is reasonably safe to always use parseFloat even if you are given an integer. If you must use the appropriate conversion, you could match for a decimal point and use the appropriate function.

提交回复
热议问题