0

Curl Get-request return numeric vales with e-, but I need json string with normal numeric format or convert numeric e- to string full numeric value

<?php


$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING ,"");
curl_setopt($ch, CURLOPT_URL, "https://api.huobi.pro/market/tickers");

$json = curl_exec($ch);
curl_close($ch);

$obj = json_decode($json, true);

$curr_pairs = array("iotabtc","manabtc");

foreach ($obj['data'] as $tick_s){
    $huobi_curr_pair = $tick_s['symbol'];

    if (in_array($huobi_curr_pair, $curr_pairs,true)){
        $tick_string = json_encode($tick_s);
        echo $tick_string;  
    }
}

?>
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Dmitry
  • 13
  • 5
  • can you show an example and the expected result ? – Yassine CHABLI Apr 06 '19 at 12:55
  • result: {"open":7.0e-5,"close":6.912e-5,"low":6.871e-5,"high":7.058e-5,"amount":2194983. 6936793807,"count":9119,"vol":153.38732516649992,"symbol":"iotabtc"} – Dmitry Apr 06 '19 at 12:59
  • expected result: {"open":0.000007,"close":0.00006925,"low":0.00006871,"high":0.00007058,"amount":2194983. 6936793807,"count":9119,"vol":153.38732516649992,"symbol":"iotabtc"} – Dmitry Apr 06 '19 at 13:01
  • what varaible contains this value in the code above ? – Yassine CHABLI Apr 06 '19 at 13:03
  • this $tick_string – Dmitry Apr 06 '19 at 13:08
  • this is not a valid json format i think – Yassine CHABLI Apr 06 '19 at 13:11
  • can you show the $tick_s – Yassine CHABLI Apr 06 '19 at 13:12
  • @Dmitry What is problematic about the `e-` notation of your floating point values? The value is the same, regardless if you use `e-` notation or write `0.00006912`. And when the JSON string is decode again you get the same correct value. When it is a display issue you can just use `number_format()` when you display the value. – Progman Apr 06 '19 at 13:29
  • @Progman you are right, e- notation well decoded to full number format. I tried decode json in database and result is ok – Dmitry Apr 06 '19 at 13:52

0 Answers0