如何将字符串方程转换为javascript中的数字? [英] How to convert string equation to number in javascript?

查看:77
本文介绍了如何将字符串方程转换为javascript中的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将字符串公式转换为javascript中的数字?

How to convert string equation to number in javascript?

说我有100 * 100或100x100,如何评估并转换为数字?

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

推荐答案

这会给你产品字符串是否使用 * x

This will give you the product whether the string is using * or x:

var str = "100x100";

var tmp_arr = str.split(/[*x]/);
var product = tmp_arr[0]*tmp_arr[1];   // 10000

这篇关于如何将字符串方程转换为javascript中的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆