math.fabs()
function returns the absolute value of a number.
math.fabs(x)
Where, x
is the number whose absolute value is to be determined.
The function returns the absolute value of x
as a floating point value.
import math
math.fabs(3)
//3.0
math.fabs(-3)
//3.0
math.fabs(-3.142)
//3.142
fabs(10)
//10
fabs(-50)
//50
fabs(100.11)
//100.11
As shown above, the absolute value of a positive number is equal to the number itself, while the absolute value of a negative number is equal to its positive counterpart.