PHP | gmp_intval() Function
Last Updated :
20 Jun, 2021
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
<?php
$x = gmp_intval( "2147" ) . "\n" ;
echo gmp_strval( $x ) . "\n" ;
?>
|
Output:
2147
Program 2: The program below demonstrates the working of gmp_intval() when GMP number is passed as an argument.
php
<?php
$num = gmp_init( "1111" , 2);
$x = gmp_intval( $num );
echo gmp_strval( $x ) . "\n" ;
?>
|
Output:
7
Reference:
http://php.net/manual/en/function.gmp-intval.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...