Bitcoin Forum
December 12, 2017, 07:12:29 PM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: [ANN] Bitcoin currency wrapper for PHP  (Read 736 times)
miso
Jr. Member
*
Offline Offline

Activity: 37


View Profile
February 19, 2014, 03:58:36 PM
 #1

Bitcoin currency wrapper for PHP | version alpha

Bitcoin currency wrapper is collection of number wrappers with adjustable precision for PHP.

Github
https://github.com/misog/btc-currency-wrapper-php

Units
  • Bitcoin (BTC) = 1 BTC
  • Satoshi (sBTC) = 0.00000001 BTC
  • Centbitcoin (cBTC) = 0.01 BTC
  • Milibitcoin (mBTC) = 0.001 BTC
  • Microbitcoin (uBTC) = 0.000001 BTC
  • Atomicbitcoin (atomicBTC) = currently Satoshi

Arithmetic and logical operations
  • sub
  • mul
  • div
  • abs
  • less
  • greater
  • equals

Classes and structure
- Number
   - Currency extends Number
      - BTC extends Currency
         - cBTC extends BTC
         - mBTC extends BTC
         - uBTC extends BTC
         - sBTC extends BTC
         - atomicBTC extends BTC
      - EUR extends Currency

Usage examples
   
Code:
/* Basic operations */
$btc1 = new BTC("1");
$btc2 = new BTC("0.005");
$btc3 = $btc1->add($btc2);
echo $btc1->getValue(); // "1.00000000"
echo $btc2->getValue(); // "0.00500000"
echo $btc3->getValue(); // "1.00500000"

/* Operations with different units */
$btc = new BTC("2");
$s_btc = new sBTC("1"); // Satoshi
echo $btc->add($s_btc)->getValue(); // "2.00000001"
echo $s_btc->add($btc)->getValue(); // "200000001"
echo $s_btc->add($btc)->getBitcoinValue(); // "2.00000001"

/* Unit conversion */
$converted_btc = new BTC($s_btc);
echo $converted_btc->getValue(); // "0.00000001"
$converted_satoshi = new sBTC($btc);
echo $converted_satoshi->getValue(); // "200000000"

/* Precision */
$btc = new BTC("2");
$result = $btc->div(new Number('3'));
echo $result->getValue(); // "0.66666666" (truncated), not rounded "0.66666667" - better lost Satoshi than arise Satoshi
   
License
MIT - http://opensource.org/licenses/MIT

Donations
BTC: 1ByESbFGcfqcQU5fV2TNoHj7VdUAT6HsjJ
1513105949
Hero Member
*
Offline Offline

Posts: 1513105949

View Profile Personal Message (Offline)

Ignore
1513105949
Reply with quote  #2

1513105949
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1513105949
Hero Member
*
Offline Offline

Posts: 1513105949

View Profile Personal Message (Offline)

Ignore
1513105949
Reply with quote  #2

1513105949
Report to moderator
1513105949
Hero Member
*
Offline Offline

Posts: 1513105949

View Profile Personal Message (Offline)

Ignore
1513105949
Reply with quote  #2

1513105949
Report to moderator
BitCoinDream
Legendary
*
Offline Offline

Activity: 1246

The revolution will be digital


View Profile
February 19, 2014, 04:31:38 PM
 #2

any demo ?

miso
Jr. Member
*
Offline Offline

Activity: 37


View Profile
February 19, 2014, 04:53:07 PM
 #3

any demo ?
Not yet. You can use usage examples as demo (just add <br> or echo separately).

var_dump(new BTC("1.1234")); should help too.

Documentation is needed and some changes will be made in the future. Tests are needed also. This is alpha.
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!