Bitcoin Forum
June 22, 2024, 08:50:31 PM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [ANN] Bitcoin currency wrapper for PHP  (Read 839 times)
miso (OP)
Newbie
*
Offline Offline

Activity: 37
Merit: 0


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
BitCoinDream
Legendary
*
Offline Offline

Activity: 2338
Merit: 1204

The revolution will be digital


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

any demo ?

miso (OP)
Newbie
*
Offline Offline

Activity: 37
Merit: 0


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:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!