I am seeing strange behavior with unsigned integer variables on PHP. Following code:
$uint64 = 11689184649718456000;
$int64 = (int)$uint64;
var_dump($uint64);
var_dump($int64);
$str = number_format($uint64,0,"","");
var_dump($str);
Output is:
float(1.1689184649718E+19)
int(-6757559423991095296)
string(20) "11689184649718456320"
What's causing the wrong outputs here?
In the End: What do I want to achieve?
- Receive an unsigned integer (uint64) via API
- Convert it to an unsigned integer
- Store it in a database (because PostgreSQL doesn't support unsigned integers)
- Get it from the Database
- Convert it back to an unsigned integer (uint64)