Seems like you're using json_decode
. It will convert numbers to integers where possible, otherwise float:
// 32bit integers
var_dump(json_decode("2147483647")); // int(2147483647)
var_dump(json_decode("2147483648")); // float(2147483648)
// 64bit integers
var_dump(json_decode("9223372036854775807")); // int(9223372036854775807)
var_dump(json_decode("9223372036854775808")); // float(9.2233720368548E+18)
You can use JSON_BIGINT_AS_STRING
flag so that json_decode
decodes large integers as their original string value:
// 32bit integers
var_dump(json_decode("2147483647", false, 512, JSON_BIGINT_AS_STRING)); // int(2147483647)
var_dump(json_decode("2147483648", false, 512, JSON_BIGINT_AS_STRING)); // string(10) "2147483648"
// 64bit integers
var_dump(json_decode("9223372036854775807", false, 512, JSON_BIGINT_AS_STRING)); // int(9223372036854775807)
var_dump(json_decode("9223372036854775808", false, 512, JSON_BIGINT_AS_STRING)); // string(19) "9223372036854775808"
Note that the number-as-a-string is not really useful for arithmetic e.g. you cannot add or multiply from it without it (auto) converting to float.