将负数 (-) 转为正常数
所以我有两个变量,当一个变量除以另一个变量时,会得到负数
-1、-2、-3
...等等。
我需要的是将 -2 放入一个变量中,该变量是 2 而不是 -2
如何实现这一目标?
这是我得出 - 值的代码:
var slideNumberOn = (left_indent / divWidth);
我发现了类似下面的内容,但它不起作用:
var slideNumberOn = (left_indent / divWidth);
var slideNumberOnNoMinus = slideNumberOn.replace('-',"");
So I have two variables which when one is divided by the other will give me a negative number
-1, -2, -3
...and so on.
What I need is to get this, let's say, -2 into a variable which is 2 not -2
How can one achieve this?
This is my code to come up with the - value:
var slideNumberOn = (left_indent / divWidth);
i found something like the below but it does not work:
var slideNumberOn = (left_indent / divWidth);
var slideNumberOnNoMinus = slideNumberOn.replace('-',"");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
绝对值。
Absolute value.
这只是数学,乘以-1。
Its just math, multiply times -1.
一个更面向数学的答案,但不再正确的是乘以-1,
a more maths orientated answer but no more correct is to multiply by -1,
或者,更简洁地说,
Or, more succinctly,
我认为你需要 abs
You need abs i think
使用
Math.abs(number)
:Use
Math.abs(number)
: