Basically, the reverse of abs. If I have:
if ($this.find(\'.pdxslide-activeSlide\').index() < slideNum - 1) {
slideNum = -slideNum
}
console.log(slideNu
var x = 100;
var negX = ( -x ); // => -100
If you don't feel like using Math.Abs * -1 you can you this simple if statement :P
if (x > 0) {
x = -x;
}
Of course you could make this a function like this
function makeNegative(number) {
if (number > 0) {
number = -number;
}
}
makeNegative(-3) => -3 makeNegative(5) => -5
Hope this helps! Math.abs will likely work for you but if it doesn't this little
The reverse of abs is Math.abs(num) * -1
.
var i = 10;
i = i / -1;
Result: -10
var i = -10;
i = i / -1;
Result: 10
If you divide by negative 1, it will always flip your number either way.
num * -1
This would do it for you.
In vanilla javascript
if(number > 0)
return -1*number;
Where number above is the positive number you intend to convert
This code will convert just positive numbers to negative numbers simple by multiplying by -1