Data is not correct in preview and response laravel [duplicate] - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Saturday, April 1, 2023

Data is not correct in preview and response laravel [duplicate]

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. Please Help I don't know is this laravel issue or php or something else.



source https://stackoverflow.com/questions/75901476/data-is-not-correct-in-preview-and-response-laravel

No comments:

Post a Comment