I'm trying to write a basic PHP NOK to BTC / BTC to NOK conversion.

I'm not that great in math and It's confusing me on how to completely convert it.. & also I'm having trouble with splitting the links data (link below), to determine the currency.

(NOK = Norwegian Krone) (BTC = Bitcoin)

This is what I'm using to determine how much 1 BTC costs in NOK.

http://data.mtgox.com/api/1/BTCNOK/ticker_fast

So for example 1 BTC = 4478.17724 NOK (currently)

So I want to be able to enter something like

$nok = 100.00; // How much NOK I have / Trying to convert

$BTC = 4478.17724; //How much 1 BTC in NOK costs

This may sound stupid, but what math functions would I need to use to determine how much of 1 BTC I would get for how much $nok I have?

I would assume divide BTC by NOK , but I feel like that isn't correct.

Second, how would I extract the number "4478.17724" (for example) from ttp://data.mtgox.com/api/1/BTCNOK/ticker_fast

I know I can use str_split() or explode, but Is that the right approach? just assuming the placement of the number rather then searching an array for it.

Thanks again for all the help and replies.

有帮助吗?

解决方案

The site is returning JSON so you would use something like http://nz1.php.net/json_decode to decode the JSON and access the data.

As your exchange rate is shown relative to BTC, to convert you would do the following.

$nok/$BTC i.e. you would divide your $nok amount by the exchange rate.

So in your example 100/4478.17724 = 0.0223305 BTC.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top