我需要在JavaScript中执行数学计算,但我不确定如何执行。
公式如下:
result = (scale * weighting) / 2
其中的结果我需要两位小数。
我需要在JavaScript中执行的示例公式可能是:
result = ((3 * 2) + (2 * 1.5)) / 2
我也不确定是否也要将它转换为int。
发布于 2011-10-04 22:20:04
发布于 2011-10-04 22:22:09
不完全确定您想要什么,但这可能会有所帮助:
result = Math.round(((scale * weighting) / 2) * 100) / 100;
发布于 2011-10-04 22:24:26
在JavaScript中,所有数字都是一个浮点数。不需要显式类型转换。
参考:http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html (搜索"The Number Data Type“)
https://stackoverflow.com/questions/7649328
复制相似问题