Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

perl
communitycreator

What is abs() in Perl?

harris910

The abs() function returns the absolute value of a number.

Figure 1 shows the mathematical representation of the abs() function.

Figure 1: Mathematical representation of abs() function

Syntax

abs(num)

num is the number whose absolute value is required

Parameter

The abs() function takes a number as a parameter.

Return value

The abs() function returns the absolute value of a number passed as a parameter.

If a string is passed to this function it returns 0.

Code


#positive number 
print "The value of abs(10) : ".abs(10). "\n";

#zero 
print "The value of abs(0) : ".abs(0). "\n";

#negative number 
print "The value of abs(-10) : ".abs(-10). "\n";

#string
print "The value of abs(str) : ".abs("str"). "\n";

RELATED TAGS

perl
communitycreator
RELATED COURSES

View all Courses

Keep Exploring