'I want to convert a negative int/ double value into positive of the same
I want to convert a negative int/ double value into positive of the same, and use it for further calculations..i tried using %2 but the value turns out to be -0.0. It would be a great help if someone could help me out with this.
Solution 1:[1]
In Dart you can do like this
value.abs()
In Kotlin you can do like this
value.absoluteValue
In JavaScript you can do like this
Math.abs(value)
Solution 2:[2]
If you only want to change negative numbers you could do:
if(num < 0)
num *= -1;
I'm just reiterating what diggersworld commented...
Solution 3:[3]
In Kotlin you can do it like this:
yourValue.absoluteValue
Or smth like this:
abs(yourValue: Double)
Also, check this out for more info: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.math/absolute-value.html
Solution 4:[4]
For Dart
Example, replace "-50" with your value or variable.
print((-50).abs());
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | mban |
| Solution 3 | Alex Koba |
| Solution 4 | Kamal Panara |
