Perl Topics





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Perl Tutorial
Introduction Introduction
Installing Perl Installing Perl
Basics of Perl Basics of Perl
Scalar Variables Scalar Variables
Operators Operators
Control Structures Control Structures
Lists Lists
Array Array
Arrays Manipulation Arrays Manipulation
Arrays Functons Array Functions
Hash Hash
Hash Functions Hash Functions
String Functions String Functions
Regular Expression Regular Expression
Regular Expression Functions Regular Expression Functions
Numerical Functions Numerical Functions
List Functions List Functions
User Defined Function User Defined Function
File Handling File Handling
Forums Ask Your Doubts
Feedback Feedback
 





Numerical Functions in Perl


Tutorials Perl

Topic

What are Numerical Functions in Perl?



Explanation
int() Function:

The int() function returns the integer part of a number.

Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    $int1 = int(40.12);
    $int2 = int(60.13);
    print "Integer part of 40.12 is : $int1\n";
    print "<br>";
    print "Integer part of 60.13 is : $int2\n";
Result:
    Integer part of 40.12 is : 40
    Integer part of 60.13 is : 60  
rand() Function:

The rand() function is used to retrieve the next pseudo random number.

Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    $rand1 = rand();
    print "Get any random  number:", $rand1 ,"\n";
    print "<br>";
    $rand2 = rand(100);
    print "Get random number till 100:", $rand2 ,"\n";
Result:
    Get any random number:0.18963623046875
    Get random number till 100:62.127685546875 
sqrt() Function:

The sqrt() function is used to return the square root value for a number.

Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";   
    $sqr = sqrt(4);
    print "The Square root of 4 is:: $sqr\n";
Result:
    The Square root of 4 is:: 2 
srand() Function:

The srand() function seed the random number generator.

Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";   
    $rand1 = srand();
    print "Get any random number:", $rand1 ,"\n";
Result:
    Get any random number:1 
abs() Function:

The abs() function is used to get the absolute value for a numeric value, returns zero if a string is passed as argument.

Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    $abs1 = abs(11.22);
    $abs2 = abs("VBN");
    $abs3 = abs(10);
    $abs4 = abs(-10);
    print "$abs1 <br>";
    print "$abs2 <br>";
    print "$abs3 <br>";
    print "$abs4 <br>";
Result:
    11.22
    0
    10
    10 
exp() Function:

The exp() function returns the exponential value of "e" to the power of the argument taken by the function.

Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    $ret_val = exp(1);
    print "Exponetial of 1 is: $ret_val\n";
Result:
    Exponetial of 1 is: 2.71828182845905 





A Note
Simple introduction, basic CGI perl programming codes with examples. Do send your feedback or suggestions on this tutorial. This is a copyright content.

Other Links

web hosting