PHPackages                             lukaszwit/currency - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lukaszwit/currency

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lukaszwit/currency
==================

Currency handling with float operations safe

0.3.0(11y ago)019MITPHPPHP ~5.4

Since Nov 10Pushed 11y ago1 watchersCompare

[ Source](https://github.com/lukaszwit/currency)[ Packagist](https://packagist.org/packages/lukaszwit/currency)[ RSS](/packages/lukaszwit-currency/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

Currency
========

[](#currency)

[![Latest Stable Version](https://camo.githubusercontent.com/86811a4afaa77b81832ae237c5ec8efe68d8ea52bd26ef32859e04ee7dd7ab90/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c756b61737a7769742f63757272656e63792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lukaszwit/currency)[![Latest Version](https://camo.githubusercontent.com/82498dc64f97ca4b099ece74237dbba586ae0b6e77bfa599a1617a647cb01fc0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6c756b61737a7769742f63757272656e63792e7376673f7374796c653d666c61742d737175617265)](https://github.com/lukaszwit/currency/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/480cad84216bbad8d34e81fc7040eede9fcdea19ea5259bb6eeb38e677b97871/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6c756b61737a7769742f63757272656e63792f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/lukaszwit/currency)[![Code Coverage](https://camo.githubusercontent.com/62b48d8ed40d3da7d66671f01ca27e4a01daaa034ef4fbb50637619c041ca146/687474703a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6c756b61737a7769742f63757272656e63792e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/lukaszwit/currency/)[![Quality Score](https://camo.githubusercontent.com/f0e8c5d6dec85b09668a60df275b05de88dc79fddf23495e6a1c8c1ae05877c9/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6c756b61737a7769742f63757272656e63792e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/lukaszwit/currency)[![Total Downloads](https://camo.githubusercontent.com/d520d9efb06374cf96c40839459caaede7ebe0b688a7a1dc0e392037ceccfdee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c756b61737a7769742f63757272656e63792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lukaszwit/currency)

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.

See how floats work in PHP -

See what happen when you relies on float precision -

This package also supports well-known cryptocurrencies listed in wikipedia - [http://en.wikipedia.org/wiki/Cryptocurrency#List\_of\_cryptocurrencies](http://en.wikipedia.org/wiki/Cryptocurrency#List_of_cryptocurrencies)

Install
-------

[](#install)

First you need to install SPL\_Types - PECL extension:

```
$ pecl install SPL_Types
```

If SPL\_Types is installed you can now install currency package via Composer:

```
$ composer require lukaszwit/currency
```

Usage
-----

[](#usage)

```
