2014-02-10 22 views
0

基本上,我試圖將Nok轉換成BTC和BTC轉換成Nok。轉換貨幣(BTC到Nok),不確定如何用數學方法在php

我必須挪威克朗BTC的工作,我只是隨便與BTC到諾克有點問題......

這是我到目前爲止有:

<?php 
public function increase_by_percent($btc) { 


    $math = $btc/10; 

    return $btc + $math; 
    //current BTC Rate + 10% 
} 

public function get_current_btc() { 
    /** Gets current Nok value of BTC , Result = Nok Currency = 1BTC. */  
    $json = file_get_contents("http://www.data.mtgox.com/api/1/BTCNOK/ticker_fast"); 
    $obj = json_decode($json, true); 
    //var_dump(json_decode($json, true)); 
    return $obj["return"]["last_local"]["value"]; 
} 

public function convert_to_btc($nok /** How much NOK */, $btc /** How much BTC is    worth*/) { 
    /** gives them the estimated amount of BTC they will get based upon how much Nok they have, and the set value of the BTC */ 
    $newbtc = $nok/$btc; 

    return $newbtc; 
} 
/** vvv This is where i'm mainky stuck at */ 
public function convert_to_nok($btc /** How much BTC */) { 
    $btc_price = $this->increase_by_percent($this->get_current_btc()); //   = "our" BTC price 

    $newnok = ""; 
    return $newnok; 
} 
?> 

我」什麼m試圖基本上得到他們想要多少BTC(就像他們輸入0.0005),它會根據字符串將其轉換爲Nok貨幣$btc_price

再次感謝。數學上我有點困惑。我正確地處理這個問題嗎?

+0

這是數學問題具體還是它與PHP有關?如果後者 - 什麼是數學公式,你不能轉換爲PHP?假設你有一個數字'42',你會如何在一張紙上增加10%'? – zerkms

+0

沒有它的PHP,PHP的工作正常。我已經能夠將數字增加10%。我將php包含給大家看看它是如何工作的。問題是將它轉換爲Nok(一種不同的貨幣,這是在$ btc_price和$ btc_price(nok))= 1BTC) – user3106858

+0

那麼問題是什麼? – zerkms

回答

0

如果你的轉化率[R是一個BTC的價格,NOK表示(這似乎是你的URL的方向),那麼你ň NOC RESP的量之間的轉換。使用這些公式b BTC:

n = b*r 
b = n/r 

如果採取平均轉換費用考慮進去,你將在使用較小的buy值乘以當,但更大的sell值。