Bitcoin currency wrapper for PHP |
version alphaBitcoin currency wrapper is collection of number wrappers with adjustable precision for PHP.
Githubhttps://github.com/misog/btc-currency-wrapper-phpUnits- 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 /* 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
LicenseMIT -
http://opensource.org/licenses/MITDonationsBTC: 1ByESbFGcfqcQU5fV2TNoHj7VdUAT6HsjJ