#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2017
    Posts
    1
    Rep Power
    0

    Question getting a percentage and adding it to content


    im working on a json from this site. https://btc-e.com/api/3/ticker/btc_usd
    im trying to get the "last" key and
    im trying to echo my own premiunm exchange rate.by getting 10% of the last key and add it up to the last key
    my codes was like this.
    <code>
    <?php
    $url = "https://btc-e.com/api/3/ticker/btc_usd";
    $fileGet = file_get_contents($url);
    $json = json_decode($fileGet, TRUE);
    $json = $json["ticker"]["last"];
    $premium = 10; //in percentage
    $premium = $premium / 100;
    $dollar_amount = $premium * $json;
    $customer_price = $json + $dollar_amount;
    echo $customer_price;
    ?>
    </code>

    there was no error indicated.but it just printed "0" on the screen.
    please help. i dont know where something does wrong.

    but everything work fine to line 4 $json=$json["ticker"]["last"]; because it print the correct last ticker on the browser.
    something may have when wrong after that.please help
  2. #2
  3. Forgotten Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,212
    Rep Power
    9644
    As I told you somewhere else, there is no ["ticker"] in the JSON.

    Comments on this post

    • charlion agrees : thank you so much.. that was the problem/now it works

IMN logo majestic logo threadwatch logo seochat tools logo