Skip to content

Instantly share code, notes, and snippets.

@Anderson-Juhasc
Created January 5, 2015 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Anderson-Juhasc/b3415411c78442728664 to your computer and use it in GitHub Desktop.
Save Anderson-Juhasc/b3415411c78442728664 to your computer and use it in GitHub Desktop.
Conversão de preço USD para BTC
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Conversão de preço USD para BTC</title>
</head>
<body>
<?php
$productValue = number_format(25, 2);
$satoshi = 100000000;
$tickerBtcAverage = json_decode(file_get_contents("https://api.bitcoinaverage.com/ticker/USD/"), true)[ask];
$oneUSDinSatoshi = ($satoshi / $tickerBtcAverage);
$productInSatoshi = ceil($productValue * $oneUSDinSatoshi);
$productInBTC = number_format($productInSatoshi / $satoshi, 8);
?>
<h1>Conversão de preço USD para BTC</h1>
<p>
<strong>Valor do Produto:</strong> $ <?php echo $productValue; ?>
</p>
<p>
<strong>Cotação:</strong> $ <?php echo $tickerBtcAverage; ?>
</p>
<p>
<strong>$ 1.00 em satoshis:</strong> <?php echo $oneUSDinSatoshi; ?>
</p>
<p>
<strong>Valor do produto em satoshis:</strong> <?php echo $productInSatoshi; ?>
</p>
<p>
<strong>Valor do produto em BTC:</strong> <?php echo $productInBTC; ?>
</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment