I've got an API that returns the value of: USD/Bitcoin & USD/GBP.
{"USDBITCOIN":"4251.27", "USDGBP":"0.758659"}
To calculate the exchange rate of GBP/Bitcoin, I simply divide the the value of the GBP by Bitcoin, because they are both USD based.
How would calculate the exchange rate of Bitcoin/GBP? It may be really simple, but it's really baffling me. I've got the below to calculate
app.js
xOfy(unit, value) {
return unit / value;
}
yOfX(unit, value) {
return unit * value;
}
xOfy(gbp, bitcoin)
// 0.00018
yOfx(bitcoin, gbp)
// 3225.26
You simply divide 1 by the resulting value:
1 / (USDGBP * USDBITCOIN)
In this case, that'd be:
1 / (0.758659 * 4251.27) = 0.0003100521146296338
The 1 itself comes from the fact 4251.27 USD is how much 1 Bitcoin is worth.