Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to convert a negative int/ double value into positive of the same

Tags:

int

double

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.

like image 465
user3402849 Avatar asked May 23 '14 18:05

user3402849


2 Answers

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)
like image 67
Amon Chowdhury Avatar answered Nov 08 '22 22:11

Amon Chowdhury


If you only want to change negative numbers you could do:

if(num < 0)
    num *= -1;

I'm just reiterating what diggersworld commented...

like image 21
mban Avatar answered Nov 09 '22 00:11

mban