In Laravel I am trying to get data from 3rd party api but something is wrong with data.
In google chrome preview section data is correct but in response data is wrong and in Mysql DB also saving wrong data.
In Preview section :
{
"buyAmount": 7.31,
"clientRate": 1.826440,
"marketRate": 1.835619,
}
In response Section :
{
"buyAmount": 7.30999999999999960920149533194489777088165283203125,
"clientRate": 1.82644099999999998118482835707254707813262939453125,
"marketRate": 1.835618999999999889638502281741239130496978759765625,
}
And In DB In JSON formate :
{
"buyAmount": 7.30999999999999960920149533194489777088165283203125,
"clientRate": 1.82644099999999998118482835707254707813262939453125,
"marketRate": 1.835618999999999889638502281741239130496978759765625,
}
I tried with round((float) ($quotedJsonString["clientRate"]), 6) But nothing worked.
Here is the code :
$url = $this->config['baseUrl'];
$response = Http::get($url);
$res = $response->json();
$response = [
"buyAmount" => round((float) ($res["buyAmount"]), 6),
"clientRate" => round((float) ($res["clientRate"]), 6),
"marketRate" => round((float) ($res["marketRate"]), 6),
];
$encoded = json_encode($response);
$quote = DBModel::create([
"response" => $encoded,
]);
In postman and other API testing tool data is correct like Chrome section Even print_r() gives me right data.
I tried with abs() function but nothing worked
{
"buyAmount" => abs(($quotedJsonString["buyAmount"])),
"clientRate" => abs(($quotedJsonString["clientRate"])),
"marketRate" => abs(($quotedJsonString["marketRate"])),
}
Please Help I don't know is this laravel issue or php or something else.