2017 © Pedro Peláez
 

library php-money

A money and currency library for handling arbitrary-precision arithmetic

image

superbalist/php-money

A money and currency library for handling arbitrary-precision arithmetic

  • Wednesday, May 3, 2017
  • by matthewgoslett
  • Repository
  • 26 Watchers
  • 3 Stars
  • 7,263 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 9 % Grown

The README.md

php-money

A money and currency library for handling arbitrary-precision arithmetic, (*1)

Author Build Status StyleCI Software License Packagist Version Total Downloads, (*2)

Installation

composer require superbalist/php-money

Usage

use Superbalist\Money\CurrencyConversionServiceProvider;
use Superbalist\Money\CurrencyFactory;
use Superbalist\Money\Money;
use Superbalist\Money\OpenExchangeRatesCurrencyConversionService;

// set default currency conversion service
// this is optional, and is only required if you're going to be converting between currencies
$service = new OpenExchangeRatesCurrencyConversionService('[[insert app id here]]');
CurrencyConversionServiceProvider::setCurrencyConversionService($service);

// set default currency
CurrencyFactory::setDefault('ZAR');

// a money object can be constructed very loosely
$a = new Money(150);
$a = new Money('150'); // recommended
$a = new Money('150.00');
$a = new Money(150.00); // not recommended, as we're trying to avoid using floating points
$a = new Money('150', CurrencyFactory::make('USD'));

// basic operations on numbers
$a = new Money('150.55');
$b = new Money('99.45');
$c = $a->add($b); // 250

$a = new Money('300.00');
$b = new Money('2');
$c = $a->divide($b); // 150

// comparing numbers
$a = new Money('0.33');
$b = new Money('0.33');
$c = $a->equals($b); // true
$c = $a->isGreaterThan($b); // false
$c = $a->isGreaterThanOrEqualTo($b); // true
$c = $a->isLessThan($b); // false

// convert a monetary value from currency A to currency B
$a = new Money('100', CurrencyFactory::make('ZAR'));
$b = $a->toCurrency(CurrencyFactory::make('USD'));

// format a number for display
$a = new Money('123.9999');
echo $a->format(); // 123.99
echo $a->display(); // R123.99

// handling value added tax
$a = new Money('100');
$rate = '0.14';
$b = $a->calculateVat($rate); // 14
$c = $a->add($b); // 114
$d = $c->calculateNetVatAmount($rate); // 100

// min & max
$a = new Money('100');
$b = new Money('101');
$c = $a->max($b); // 101
$d = $a->min($b); // 100

// ...see classes for full list of methods

The Versions

03/05 2017

dev-master

9999999-dev

A money and currency library for handling arbitrary-precision arithmetic

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-bcmath *

 

The Development Requires

by Superbalist.com a division of Takealot Online (Pty) Ltd

03/05 2017

2.0.0

2.0.0.0

A money and currency library for handling arbitrary-precision arithmetic

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-bcmath *

 

The Development Requires

by Superbalist.com a division of Takealot Online (Pty) Ltd

03/05 2017

dev-default-rounding-half-up

dev-default-rounding-half-up

A money and currency library for handling arbitrary-precision arithmetic

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-bcmath *

 

The Development Requires

by Superbalist.com a division of Takealot Online (Pty) Ltd

21/04 2017

1.0.5

1.0.5.0

A money and currency library for handling arbitrary-precision arithmetic

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-bcmath *

 

The Development Requires

by Superbalist.com a division of Takealot Online (Pty) Ltd

01/02 2016

1.0.4

1.0.4.0

A money and currency library for handling arbitrary-precision arithmetic

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-bcmath *

 

The Development Requires

by Superbalist.com a division of Takealot Online (Pty) Ltd

01/02 2016

1.0.3

1.0.3.0

A money and currency library for handling arbitrary-precision arithmetic

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-bcmath *

 

The Development Requires

by Superbalist.com a division of Takealot Online (Pty) Ltd

27/01 2016

1.0.2

1.0.2.0

A money and currency library for handling arbitrary-precision arithmetic

  Sources   Download

The Requires

  • php >=5.4.0
  • ext-bcmath *

 

The Development Requires

by Superbalist.com a division of Takealot Online (Pty) Ltd

27/01 2016

1.0.1

1.0.1.0

A money and currency library for handling arbitrary-precision arithmetic

  Sources   Download

The Requires

  • php >=5.4.0
  • ext-bcmath *

 

by Superbalist.com a division of Takealot Online (Pty) Ltd

22/01 2016

1.0.0

1.0.0.0

A money and currency library for handling arbitrary-precision arithmetic

  Sources   Download

The Requires

  • php >=5.4.0
  • ext-bcmath *

 

by Superbalist.com a division of Takealot Online (Pty) Ltd