PHP | gmp_intval() Function (original) (raw)

Last Updated : 11 Jul, 2025

The gmp_intval() is an inbuilt function in PHP which converts a GMP number to an integer. Here GMP refers to GNU Multiple Precision which is for large numbers.
Syntax:

int gmp_intval ( $num )

Parameters: The function accepts a single parameter $num which is a GMP number and returns its integer value. This parameter can be a GMP object in PHP version 5.6 and later, or we are also allowed to pass a numeric string provided that it is possible to convert that string to a number.
Return Value: The function returns integer value of the given GMP number $num
Examples:

Input : $num = "2147483647" Output : 2147483647

Input : $num = "12" Output : 12

Note: If a numeric string is passed as an integer, it returns the same integer (except above PHP integer limit). But if a GMP number is passed, it returns the integer value of a GMP number.
Below programs illustrate the use of gmp_intval() function:
Program 1: The program below demonstrates the working of gmp_intval() function when numeric string is passed as an argument.

php `

`

Output:

2147

Program 2: The program below demonstrates the working of gmp_intval() when GMP number is passed as an argument.

php `

x=gmpintval(x = gmp_intval(x=gmpintval(num); // prints the integer value of a gmp number // gmp_strval converts GMP number to string // representation in given base(default 10). echo gmp_strval($x) . "\n"; ?>

`

Output:

7

Reference:
https://www.php.net/manual/en/function.gmp-intval.php