Php代码在将符号转换为整数时打印多行

时间:2015-10-08 20:08:57

标签: php api

我正试图从cryptopia api获取'LastPrice'和'Label'。我做对了,但显示的Lastprice显示为符号1.124E-5 当我使用number_format($ price,8)时,输出显示价格的多行,其中一行具有价格,而其他行具有全部零,如:

  

0.00000000   0.00000000   XVI / LTC   0.00001124   0.00000000

但它应该像

  

XVI / LTC   0.00001124

<?php

    // construct the query with our apikey and the query we want to make
    $endpoint = 'https://www.cryptopia.co.nz/api/GetMarket/2422';
    // setup curl to make a call to the endpoint
    $session = curl_init($endpoint);
    // indicates that we want the response back
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
    // exec curl and get the data back
    $data = curl_exec($session);
    // remember to close the curl session once we are finished retrieveing the data
    curl_close($session);
    // decode the json data to make it easier to parse the php
    $search_results = json_decode($data, true);
    if ($search_results === NULL) die('Error parsing json');
    //print_r($search_results);
    echo '<table>';

    foreach ($search_results as $coin) {

    $name = $coin["Label"];
    $price = $coin["LastPrice"];


    echo '<tr><td>' . $name . '</td></tr>';
    echo '<tr><td>' . number_format($price, 8) . '</td></tr>';
    }
        echo '</table>';

    ?>

需要你的帮助

0 个答案:

没有答案