Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是我的功能:
var ans=(X*X)/(Y+Z);
当我输入10,20和10- 分别 - 加法位出现2010和 not 30。我怎样才能解决这个问题?
10
20
2010
30
确保首先将字符串转换为数字:
var X = "10"; var Y = "20"; var Z = "10"; X = +X; // unary plus operator converts to a number Y = Number(Y); // or use the Number function Z = parseInt(Z, 10); // or parseInt var ans=(X*X)/(Y+Z);