I have this RAW JSON being returned and when I apply json_decode to access the data as an array it turns the trackingNumber into scientific notations. Is there any possible way to avoid this without compromising/rounding the integer or can I loop through the RAW JSON without decoding it? I've tried changing the precision and formatting it with number_format and both did work to an extent. However, there were some changes in the numbers around the middle of the integer as if it was rounded.
Original JSON data:
{
"data": {
"shipments": [
{
"packages": [
{
"responseDetails": {
"trackingNumber": 420217949361269903504794752430
}
}
]
}
]
}
}
When json_decode gets involved:
{
"data": {
"shipments": [
{
"packages": [
{
"responseDetails": {
"trackingNumber": 4.202179493612699e+29,
}
}
]
}
]
}
}
Changing precision:
<?php
ini_set('precision', 30);
$trackingNumber = 4.202179493612699e+29;
print $trackingNumber;
// Displays: 420217949361269887002807894016
?>
Using number_format():
<?php
$trackingNumber = number_format(4.202179493612699e+29, 0, '.', '');
print $trackingNumber;
// Displays: 420217949361269887002807894016
?>