PHPackages                             amoreno/currency-formatter - 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. amoreno/currency-formatter

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

amoreno/currency-formatter
==========================

PHP Lib for formatting currencies according to currency code

0.4.0(9y ago)04.6kMITPHP

Since Nov 7Pushed 9y ago1 watchersCompare

[ Source](https://github.com/angelxmoreno/php-currency-formatter)[ Packagist](https://packagist.org/packages/amoreno/currency-formatter)[ RSS](/packages/amoreno-currency-formatter/feed)WikiDiscussions master Synced today

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

PHP Currency Formatter
======================

[](#php-currency-formatter)

PHP Lib for formatting currencies.

Why make this?
--------------

[](#why-make-this)

Many of the Currency Formatters I found relied on locales. My current needs for a formatter required the decoupling of locale knowledge.

Installation
------------

[](#installation)

```
composer require axm/currency-formatter
```

Usage
-----

[](#usage)

The formatter is powered by the Currency Collection which holds an array of formatting rules. You can create your own collection and then set it to the Formatter:

```
$settings = [
	'currency_symbol' => '$',
	'decimal_spaces' => 2,
	'decimal_separator' => '.',
	'thousand_separator' => ','
];

$config = new Config('USD', $settings);

$collection = new Collection();
$collection->push($config);

Formatter::setCollection($collection);
echo Formatter::format('1234.56', 'USD'); // $1,234.56 USD
```

The above seperates the Config, Collection and Formatter classes for maximum flexibility. It allows you to define your own sets of rules and only load the rules you actually need for a minor performance boost.

However, The above seems like a bit of setup. This is where the Loader class comes in:

```
/*
Given a JSON string of currency settings:
[
  {
    "iso_code": "USD",
    "currency_symbol": "$",
    "decimal_spaces": 2,
    "decimal_separator": ".",
    "thousand_separator": ",",
	 "label": "Dollars"
  },
  {
    "iso_code": "GBP",
    "currency_symbol": "£",
    "decimal_spaces": 2,
    "decimal_separator": ",",
    "thousand_separator": ".",
	 "label": null // if omitted will use the iso_code
  },
  {
    "iso_code": "CLP",
    "currency_symbol": "$",
    "decimal_spaces": 0,
    "decimal_separator": ",",
    "thousand_separator": "."
  }
]
*/

$settings = json_decode(file_get_contents(json_file));
Loader::fromArray(settings);

// Your Format class now has a collection with 3 currency rules
echo Format::(1234.56, 'USD'); // $1,234.56 Dollars
echo Format::(1234.56, 'GBP'); // £1.234,56 GBP
echo Format::(1234.56, 'CLP'); // $1.235 CLP
```

So long as you have an array in the expected format, using the Loader is the best way to go.

Customizing the output
----------------------

[](#customizing-the-output)

If you wish to more granular control you can either create your own set of rules or override the exisitng ones like so:

```
//creating a custom rule
Formatter::getCollection()->push([
	'iso_code' => 'USD2',
	'currency_symbol' => '',
	'decimal_spaces' => 2,
	'decimal_separator' => '.',
	'thousand_separator' => ',',
	'label' => ' big ones'
]);
Formatter::format(1234.56, 'USD2'); // 1,234.56 big ones

//overriding an existing rule
echo Format::(1234.56, 'USD2', [
	'currency_symbol' => '$$ ',
	'decimal_spaces' => 4,
	'label' => 'bucks'
]); // $$ 1,234.5600 big ones
```

Tests
-----

[](#tests)

The library uses Kahlan for testing. To run tests make suer you have the require-dev modules installed:

```
composer install
./bin/kahlan
```

License
-------

[](#license)

MIT License

Copyright (c) 2016 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~47 days

Total

3

Last Release

3429d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/58aebae1bf475954887c4c975a24950aa32c0dd34026400fa0303f7a43672389?d=identicon)[angelxmoreno](/maintainers/angelxmoreno)

---

Top Contributors

[![angelxmoreno](https://avatars.githubusercontent.com/u/363479?v=4)](https://github.com/angelxmoreno "angelxmoreno (22 commits)")

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/amoreno-currency-formatter/health.svg)

```
[![Health](https://phpackages.com/badges/amoreno-currency-formatter/health.svg)](https://phpackages.com/packages/amoreno-currency-formatter)
```

###  Alternatives

[eftec/statemachineone

A state Machine library for business processes

1144.0k](/packages/eftec-statemachineone)[falseclock/advanced-cms

A PHP Library that allows you to decode and manipulate CAdES or in other words CMS Advanced Electronic Signatures described in ETSI standart TS 101 733.

223.4k](/packages/falseclock-advanced-cms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
