Skip to content
Related Articles

Related Articles

Perl | int() function
  • Last Updated : 25 Jun, 2019

int() function in Perl returns the integer part of given value. It returns $_ if no value provided. Note that $_ is default input which is 0 in this case. The int() function does not do rounding. For rounding up a value to an integer, sprintf is used.

Syntax: int(VAR)

VAR: value which is to be converted into integer

Returns: Returns the integer part of VAR

Example 1:

# Passing positive decimal value
$int_val = int(19.8547);
print"Integer value is $int_val\n";
# Passing negative decimal value
$int_val = int(-18.659);
print"Integer value is $int_val\n";


Integer value is 19
Integer value is -18

Example 2:

# Passing fractional positive value
$int_val = int(17 / 4);
print"Integer value is $int_val\n";
# Passing fractional negative value
$int_val = int(-17 / 4);
print"Integer value is $int_val\n";


Integer value is 4
Integer value is -4

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :