略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: gmp_intval

2025-02-27

gmp_intval

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)

gmp_intvalConvert GMP number to integer

说明

gmp_intval(GMP|int|string $num): int

This function converts GMP number into native PHP ints.

参数

num

GMP 对象、intstring,可以按照跟在 gmp_init() 中使用字符串并自动检测 base(即当 base 等于 0 时)相同的逻辑将其解释为数字。

返回值

The int value of num.

示例

示例 #1 gmp_intval() example

<?php
// displays correct result
echo gmp_intval("2147483647") . "\n";

// displays wrong result, above PHP integer limit
echo gmp_intval("2147483648") . "\n";

// displays correct result
echo gmp_strval("2147483648") . "\n";
?>

以上示例会输出:

2147483647
2147483647
2147483648

注释

警告

This function returns a useful result only if the number actually fits the PHP integer (i.e., signed long type). To simply print the GMP number, use gmp_strval().

添加备注

用户贡献的备注

此页面尚无用户贡献的备注。

官方地址:https://www.php.net/manual/en/function.gmp-intval.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3