The abs()
function returns the absolute value of a number.
Figure 1 shows the mathematical representation of the abs()
function.
abs(num)
num
is the number whose absolute value is required
The abs()
function takes a number as a parameter.
The abs()
function returns the absolute value of a number passed as a parameter.
If a
string
is passed to this function it returns0
.
#positive numberprint "The value of abs(10) : ".abs(10). "\n";#zeroprint "The value of abs(0) : ".abs(0). "\n";#negative numberprint "The value of abs(-10) : ".abs(-10). "\n";#stringprint "The value of abs(str) : ".abs("str"). "\n";