PHPackages                             moltin/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. [API Development](/categories/api)
4. /
5. moltin/currency

ActiveLibrary[API Development](/categories/api)

moltin/currency
===============

Currency conversion and formatting

1.1.0(9y ago)106151.3k↓50%20[1 PRs](https://github.com/moltin/currency/pulls)1proprietaryPHPPHP &gt;=5.6.0

Since Mar 18Pushed 5y ago11 watchersCompare

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

READMEChangelogDependencies (3)Versions (3)Used By (1)

Currency Package
================

[](#currency-package)

[![Build Status](https://camo.githubusercontent.com/1513f2ec8d59f7fc3408dac7981f4bf7d36474188d21d829eae346dae8b1c1db/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6d6f6c74696e2f63757272656e63792e706e67)](http://travis-ci.org/moltin/currency)

- [Website](http://molt.in)
- [License](https://github.com/moltin/currency/blob/master/LICENSE)
- Version: dev

The Moltin currency composer package makes it easy to implement multi-currency pricing into your application and store the exchange data using one of the numerous data stores provided. You can also inject your own data store if you would like your data to be stored elsewhere.

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

[](#installation)

Download and install composer from `http://www.getcomposer.org/download`

Add the following to your project `composer.json` file

```
{
    "require": {
        "moltin/currency": "~1.0.0"
    }
}

```

When you're done just run `php composer.phar install` and the package is ready to be used.

Usage
-----

[](#usage)

Below is a basic usage guide for this package.

### Instantiating currency

[](#instantiating-currency)

Before you begin, you will need to know which storage, currencies and exchange method you are going to use. The exchange method defines where your exchange rates are retrieved from. The currencies method is used to retrieve your supported currencies for the current application.

In this example we're going to use the currencies file, exchange file and session for storage.

```
use Moltin\Currency\Currency as Currency;
use Moltin\Currency\Format\Runtime as RuntimeFormat;
use Moltin\Currency\Exchange\OpenExchangeRates as OpenExchange;

$currency = new Currency(new OpenExchange($app_id), new RuntimeFormat);
```

### Setting the value

[](#setting-the-value)

Now that you have Currency instantiated, you will now need to tell it what value you would like to convert. You can do this using the following method.

```
$currency->convert(9.33)->from('GBP');
```

### Getting the value

[](#getting-the-value)

The most basic action you can perform is retrieve the original value back from the method.

```
// Returns 9.33
$value = $currency->value();
```

### Formatting as a currency

[](#formatting-as-a-currency)

By default the currency is set to GBP so calling currency will format the value to a string with £ and correct decimal and thousand seperators.

```
// Returns £9.33
$value = $currency->format();
```

### Rounding to common values

[](#rounding-to-common-values)

There are a number of common pricing formats built in to make "nice" prices easy to implement. These formats changes the default value and return the object to allow for chaining.

```
// Sets value to 10.00
$currency->zeros();

// Sets value to 9.99
$currency->nines();

// Sets value to 9.50
$currency->fifty();

// Returns £9.50
$value = $currency->fifty()->format();
```

### Currency Exchange

[](#currency-exchange)

The package makes it as easy as possible to quickly switch between currencies. Before each exchange the value is reset to default to ensure the correct price is assigned.

```
// Returns ~$14.47
$value = $currency->convert(9.33)->from('GBP')->to('USD')->format();

// Returns ~14.50
$value = $currency->convert(9.33)->from('GBP')->to('USD')->fifty()->value();
```

### Resetting the value

[](#resetting-the-value)

After using exchange or any of the rounding functions to retrieve the default value you must call reset.

```
// Returns 10.00
$value = $currency->zeros()->value();

// Returns 9.33
$value = $currency->reset()->value();
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.6% 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 ~0 days

Total

2

Last Release

3348d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

1.1.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/a998c3c99f2ab63cb0535744d941499d064eba354b07d611c40aaaea9b28ee16?d=identicon)[moltin](/maintainers/moltin)

---

Top Contributors

[![chrisnharvey](https://avatars.githubusercontent.com/u/619298?v=4)](https://github.com/chrisnharvey "chrisnharvey (155 commits)")[![Axhini](https://avatars.githubusercontent.com/u/20891107?v=4)](https://github.com/Axhini "Axhini (14 commits)")[![zot24](https://avatars.githubusercontent.com/u/678498?v=4)](https://github.com/zot24 "zot24 (3 commits)")[![djonas-noip](https://avatars.githubusercontent.com/u/182177303?v=4)](https://github.com/djonas-noip "djonas-noip (2 commits)")[![JosephSilber](https://avatars.githubusercontent.com/u/1403741?v=4)](https://github.com/JosephSilber "JosephSilber (1 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (1 commits)")[![outrunthewolf](https://avatars.githubusercontent.com/u/814246?v=4)](https://github.com/outrunthewolf "outrunthewolf (1 commits)")

---

Tags

apicurrenciescurrencyexchangemoltin

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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