2017 © Pedro Peláez
 

library currency

Currency handling with float operations safe

image

lukaszwit/currency

Currency handling with float operations safe

  • Saturday, December 6, 2014
  • by lukaszwit
  • Repository
  • 1 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Currency

Latest Stable Version Latest Version Software License Build Status Code Coverage Quality Score Total Downloads, (*1)

Currency package introduces strictly typed and precision safe containers to work with currencies. Currency keeps internally amount as string (the only safe representation of floating point number in PHP). It ensures that once any amount in given currency is defined you cannot change it's type and you can type hint your methods to use nay currency or one exact currency. Internally this lib uses SplType extension and SplString class. Keeping amounts in string prevents from floats problems and lets you use high precision libraries like bcMath to process arithmetic operations., (*2)

See how floats work in PHP - http://php.net/manual/en/language.types.float.php, (*3)

See what happen when you relies on float precision - http://stackoverflow.com/questions/3726721/php-math-precision, (*4)

This package also supports well-known cryptocurrencies listed in wikipedia - http://en.wikipedia.org/wiki/Cryptocurrency#List_of_cryptocurrencies, (*5)

Install

First you need to install SPL_Types - PECL extension:, (*6)

``` bash $ pecl install SPL_Types, (*7)


If SPL_Types is installed you can now install currency package via Composer: ``` bash $ composer require lukaszwit/currency

Usage

<?php
use Currency\Eur;

$eur = new Eur;
$eur = '10'; // this is OK

$eur = 10; // but this emits UnexpectedValueException

Type hinting, (*8)

<?php
use Currency\Usd;
use Currency\AbstractCurrency as Currency;

class Example
{
    public function workWithCurrency(Currency $c)
    {

    }

    public function workOnlyWithUsd(Usd $usd)
    {

    }
}

see more examples in examples directory - https://github.com/lukaszwit/currency/tree/master/examples., (*9)

Testing

bash $ phpunit, (*10)

Contributing

Please see CONTRIBUTING for details., (*11)

Credits

License

The MIT License (MIT). Please see License File for more information., (*12)

Bitdeli Badge, (*13)

The Versions

06/12 2014

dev-master

9999999-dev

Currency handling with float operations safe

  Sources   Download

MIT

The Requires

  • php ~5.4

 

The Development Requires

by Lukasz Witczak

16/11 2014

0.3.0

0.3.0.0

Currency handling with float operations safe

  Sources   Download

MIT

The Requires

  • php ~5.4

 

The Development Requires

by Lukasz Witczak

10/11 2014

0.1.1

0.1.1.0

Currency handling with float operations safe

  Sources   Download

MIT

The Requires

  • php ~5.4

 

The Development Requires

by Lukasz Witczak

10/11 2014

0.1.0

0.1.0.0

Currency handling with float operations safe

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Lukasz Witczak