JavaScript数学计算

JavaScript数学计算,javascript,Javascript,我需要在JavaScript中执行一个数学计算,我不确定如何执行 公式如下: result = (scale * weighting) / 2 这里的结果需要两位小数 我需要在JavaScript中执行的示例公式可能是: result = ((3 * 2) + (2 * 1.5)) / 2 我也不确定是否必须将其转换为整数。: 或者,如果需要整数,则: : 或者,如果需要整数,则: 不完全确定您想要什么,但这可能会有所帮助: result = Math.round(((scale * wei

我需要在JavaScript中执行一个数学计算,我不确定如何执行

公式如下:

result = (scale * weighting) / 2
这里的结果需要两位小数

我需要在JavaScript中执行的示例公式可能是:

result = ((3 * 2) + (2 * 1.5)) / 2
我也不确定是否必须将其转换为整数。

:

或者,如果需要整数,则:

:

或者,如果需要整数,则:


不完全确定您想要什么,但这可能会有所帮助:

result = Math.round(((scale * weighting) / 2) * 100) / 100;

不完全确定您想要什么,但这可能会有所帮助:

result = Math.round(((scale * weighting) / 2) * 100) / 100;

在JavaScript中,所有数字都是浮点数。不需要显式类型转换


ref:(在JavaScript中搜索“数字数据类型”)

所有数字都是浮点数。不需要显式类型转换


ref:(搜索“数字数据类型”)

为什么不
result=(比例*权重)/2.0
?为什么不
result=(比例*权重)/2.0
?感谢提供更多信息。感谢提供更多信息。
result = Math.round(((scale * weighting) / 2) * 100) / 100;