0

I had to convert a large decimal number to hexadecimal so i use the function dechex.

So my code go like these :

$large_number = '637188198442990866068821375'
$large_hex = dechex($large_number)

but when i print the variable $large

echo $large

i got these value 7fffffffffffffff and i am very sure that i lose some precision.

What can i do to get the full precision in these operation ?

eli.rodriguez
  • 480
  • 2
  • 9
  • 22

1 Answers1

0

The largest integer that Javascript can handle is 2^52. +/- 9007199254740992

What is JavaScript's highest integer value that a Number can go to without losing precision?

You'll either need to slice up your integer before it hits Javascript or look at one of the Big Integer libraries.

Community
  • 1
  • 1
Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74