Since I'm a beginner in PHP
I can't figure it out how I should make my calculator display the zeros instead of -x at the end?
<?php
$intValue = 0;
$arrResult = json_decode(file_get_contents('http://preev.com/pulse/units:btc+usd/sources:bitfinex+bitstamp+btce'), true);
foreach($arrResult['btc']['usd'] as $key => $index){
$intValue = $intValue + $arrResult['btc']['usd'][$key]['last'];
}
echo ($intValue / 3);
$val1 = 1;
$value001usd = $val1 / $intValue / 3 / 1000;
echo " 0.001 USD Equals to $value001usd BTC";
?>
It outputs the result at the time of this post as: 402.31333333333 0.001 USD Equals to 2.7618053369126E-7 BTC
Now I need it to be " 402.31333333333 0.001 USD Equals to 0.000002761 BTC"
Use the function number_format()
to properly format the value with the number of decimals you need:
$valueBTC = $val1 / $intValue / 3 / 1000;
$textBTC = number_format($valueBTC, 10);
echo(" 0.001 USD Equals to $textBTC BTC
");
You Can Actually round your output number to whatever length you want. Here is an example echo round(1.9558334534534, 5); // Outputs 1.95583
Here is the link for php function where you can get extra help