Bootstrap FreeKB - Perl (Scripting) - Division (/)
Perl (Scripting) - Division (/)

Updated:   |  Perl (Scripting) articles

Here is the most basic example of how to divide two numbers in Perl.

#!/usr/bin/perl
use strict;
use warnings;

print (10 / 2);

 

It is much more common to store the result in a variable.

#!/usr/bin/perl
use strict;
use warnings;

my $result = (10 / 2);
print "result = $result \n";

 

Which should return the following.

5

 


Decimal numbers

By default, decimal will be used.

#!/usr/bin/perl
use strict;
use warnings;

my $result = (10.2 / 2.5);
print "result = $result \n";

 

Which should return the following.

4.08

 


Whole numbers

The integer module can be used to round to whole numbers.

#!/usr/bin/perl
use strict;
use warnings;
use integer;

my $result = (10.2 / 2.5);
print "result = $result \n";

 

Which should return the following.

5

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 9a7333 in the box below so that we can be sure you are a human.