Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Always return positive value

Tags:

c#

math

I have a number it could be negative or positive but I simply want to return the positive value.

-4 -> 4 5 -> 5 

I know I can do a simple if check, see if its zero then return it *-1 but I can't remember for the life of me what the actual Maths operator is!

Can anyone tell me what it is?

like image 716
Chris Avatar asked Dec 18 '11 13:12

Chris


People also ask

How do you always return a positive number?

ABS Formula In Excel In Excel, you compute the absolute value using the formula function ABS. With the formula =ABS(-5), Excel converts the negative to positive and gives the result 5. You can wrap a larger computation in the ABS function to make the result always positive.

Which function will return only positive value?

The abs() function is used to get the absolute (positive) value of a given number.

How do I get always positive values in C++?

a = -0.340515; to convert this into positive number I used the abs() method as: a = abs(a);


2 Answers

Use System.Math.Abs as documented here.

like image 190
Shai Avatar answered Sep 27 '22 21:09

Shai


You're looking for Math.Abs.

like image 32
SLaks Avatar answered Sep 27 '22 19:09

SLaks