David Gore
David Gore

Reputation: 185

How to change a negative number to positive?

How to make a negative number to be positive (ie. -25 to be 25) in JavaScript?

Upvotes: 1

Views: 7629

Answers (3)

Gumbo
Gumbo

Reputation: 655219

There are various ways:

var m, n = -25;
m = -1 * n;
m = -n;
m = Math.abs(n);

Upvotes: 7

Murali VP
Murali VP

Reputation: 6417

use Math.abs function

Upvotes: 1

leepowers
leepowers

Reputation: 38298

var n= -25;
var m= -1 * n;

Upvotes: 1

Related Questions