PHP: How to convert bigint from int to string?

后端 未结 4 1430
礼貌的吻别
礼貌的吻别 2020-12-04 01:44

I want to be able to convert big ints into their full string derivatives.

For example.

$bigint = 9999999999999999999;
$bigint_string = (string) $bigi         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 02:04

    Use strval().

    echo strval($bigint); // Will output "99999999999999999"
    

    EDIT: After a slightly better research (> 5000ms), I see that it is impossible to echo numbers to that precision, because PHP cannot save an integer of that size (depends on OS bit system, 32/64). Seems like it's not possible to do it without losing precision.

提交回复
热议问题