Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. function convertToBTCFromSatoshi($value){
  2. $BTC = ($value / 100000000 );
  3. return (float)$BTC;
  4. }
  5.  
  6. php > echo 10000.00000001 * 2;
  7. 20000.00000002
  8. php > echo 100000.00000001 * 2;
  9. 200000.00000002
  10. php > echo 1000000.00000001 * 2;
  11. 2000000
  12.  
  13. /** Convert Satoshis to a string that can be displayed to users.
  14. * input: $value Integer or string that can be parsed as an int.
  15. * output: string (eg: "1.00400000")
  16. */
  17. function convertToBTCFromSatoshi($value){
  18. return bcdiv( intval($value), 100000000, 8 );
  19. }
  20.  
  21. rtrim($value, "0"); // trim zeros from the right-hand side
  22.  
  23. function convertToBTCFromSatoshi($value) {
  24. $BTC = $value / 100000000 ;
  25. return $BTC;
  26. }
  27. function formatBTC($value) {
  28. $value = sprintf('%.8f', $value);
  29. $value = rtrim($value, '0') . ' BTC';
  30. return $value;
  31. }
  32. echo formatBTC(convertToBTCFromSatoshi(5000));
  33.  
  34. 0.00005 BTC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement