PHP: converting an integer of 64 bits to a string

I am trying to use a 64 bit hardcoded integer in a string variable.

Simplfied I want to do something like this:

$i = 76561197961384956;
$s = "i = $i";

This should result in s:

i = 76561197961384956

This obviously does not work, since PHP distinguishes large integers for float, therefore s:

i = 7.65611979614E+16

While some other methods, such as casting, etc., fail, I found number_format()and used it like this:

$s = "i = " . number_format($i, 0, '.', '');

But this leads to the fact that sit looks like:

i = 76561197961384960

It looks like an approximation problem, but how to fix it?

+3
source share
4 answers

, . , , .

:

$i = 76561197961384956;

. , , int .

+3

, - bcmath.

PHP Binary Calculator, , .

$i, , . PHP 32- int .

+2

php - bcmath gmp, . php6 64- .

therefore, when using large integers to distinguish them from the string or you will lose accuracy when assigning (automatic tide for float), and then use in string math libraries to further process your number.

+2
source

Have you tried using the intval () function of PHP?

-1
source

Source: https://habr.com/ru/post/1708243/


All Articles