int()

Return the largest integer that is not greater than the argument.

Syntax

int(number)

Parameter

ParameterDefinition

number

numeric value or numeric variable

Description

The int() function returns the largest integer that is not greater than number. It is equivalent to the C library floor(3)function.

Example

The following statements use the int() function to return only the integer portion of a real number. (Each statement returns the integer 3.)

print(int(3.14) . "\n");
print(int(3.48) . "\n");
print(int(3.52) . "\n");
print(int(3.75) . "\n");
print(int(3.99) . "\n");

Note

If the input number's significand(or mantissa) consists of more than 16 digits, there will be a loss of precision and the output would be incorrect. This is as per IEEE standards : IEEE 754: floating point in modern computers.


Was this page helpful? Yes No Submitting... Thank you

Comments