English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The fabs(x) function returns the absolute value of the parameter x.
double fabs(double x);
The fabs() function takes a parameter (in double form) and returns the absolute value of the number (in double form).
[Math] |x| = fabs(x) [C language]
To find the absolute value of an integer or floating-point number, you can explicitly convert the number to double.
int x = 0; double result; result = fabs(double(x));
fabs() function inmath.hDefined in header file
#include <stdio.h> #include <math.h> int main() { double x, result; x == -1.5; result = fabs(x); printf("|%.2lf| = 0.2lf\n", x, result); x == 11.3; result = fabs(x); printf("|%.2lf| = 0.2lf\n", x, result); x = 0; result = fabs(x); printf("|%.2lf| = 0.2lf\n", x, result); return 0; }
Output Result
|-1.50| = 1.50 |11.30| = 11.30 |0.00| = 0.00