Skip to content
Advertisement

multiply string in js which is both multiplier and multiplication operator

I want to transform the example string "0.45*100" in a value (45).

Another example, if I have two variables totalCost and contractVolume, and I have the string "totalCost * 1000 / contractVolume": how can I transform the string in the resulting value? ex.

JavaScript

Obs: I see a similar question, but in php, in the example he uses the method eval()

Url

Advertisement

Answer

you can also use eval() function in javascript

like —

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement