How to convert string equation to number in javascript?

前端 未结 5 968
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-20 03:04

How to convert string equation to number in javascript?

Say I have \"100*100\" or \"100x100\" how do I evaluate that and convert to a number?

5条回答
  •  有刺的猬
    2020-12-20 04:03

    use parseInt() ,The parseInt() function parses a string and returns an integer.

            parseInt("100")*parseInt("100") //10000
    

提交回复
热议问题