Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

perl
communitycreator

What is the int() function in Perl?

okwudili onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The int() function is used on a number like a decimal number. It returns the integer part. For example, 15.4 will be returned as 15 when the int() function is invoked on the number value.

Note: The int() function does not do any rounding.

Syntax

int(value)

Parameters

value: This is the value we want to convert into an integer.

Return Value

The value returned is the integer part of value.

Code example

# create some numeric values
$val1 = 12.34;
$val2 = 3/2;
$val3 = -2.555;
# get int values
$int1 = int($val1);
$int2 = int($val2);
$int3 = int($val3);
# print results
print "$val1 is $int1\n";
print "$val2 is $int2\n";
print "$val3 is $int3";
Get integer part of a value

Explanation

  • Lines 2 to 4: We create some values.
  • Lines 7 to 9: We get the integer values of our created values.
  • Lines 12 to 14: The results are printed to the console.

RELATED TAGS

perl
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring