• Status: Solved
• Priority: Medium
• Security: Public
• Views: 405

# How do I find the absolute value of a number in C++?

I have a float variable fNumber.

How do I find the absolute value of fNumber?

In Excel there is a function called ABS() that will let me find the absolute value.  What is the C++ equivalent?
0
shaolinfunk
• 2
1 Solution

Commented:
double fabs (      double x );
float fabs (       float x );
long double fabs ( long double x );

Returns the absolute value of x.

0

Commented:
check out
double fabs (      double x );
float fabs (       float x );
long double fabs ( long double x );

http://www.cplusplus.com/reference/clibrary/cmath/fabs/

``````/* fabs example */
#include <stdio.h>
#include <math.h>

int main ()
{
printf ("The absolute value of 3.1416 is %lf\n", fabs (3.1416) );
printf ("The absolute value of -10.6 is %lf\n", fabs (-10.6) );
return 0;
}
``````
0

Author Commented:
thank you!
0

Author Commented:
maybe you guys could help me with this one too:

http://www.experts-exchange.com/Programming/Languages/CPP/Q_25685893.html
0

## Featured Post

• 2
Tackle projects and never again get stuck behind a technical roadblock.