PHPackages                             openbuildings/jam-monetary - 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. openbuildings/jam-monetary

ActiveKohana-module

openbuildings/jam-monetary
==========================

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

0.2.1(6y ago)0170.3k[1 issues](https://github.com/OpenBuildings/jam-monetary/issues)1BSD-3-ClausePHPPHP ^7.1CI failing

Since Sep 5Pushed 6y ago10 watchersCompare

[ Source](https://github.com/OpenBuildings/jam-monetary)[ Packagist](https://packagist.org/packages/openbuildings/jam-monetary)[ Docs](https://github.com/OpenBuildings/jam-monetary)[ RSS](/packages/openbuildings-jam-monetary/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (29)Used By (1)

Jam Monetary
============

[](#jam-monetary)

A Jam Field to transparently use "[monetary](https://github.com/OpenBuildings/monetary)" as a Jam field, and have currency exchange arithmetic out of the box

[![Build Status](https://camo.githubusercontent.com/407c29e86f59f6d86e15a7580d40bbfc0a185ea68d249b87250dd4a35828639b/68747470733a2f2f7472617669732d63692e6f72672f4f70656e4275696c64696e67732f6a616d2d6d6f6e65746172792e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/OpenBuildings/jam-monetary)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/d72cd99286ff62fa897b260374d3e2ca22b6c4dc13b79cc3cf43270aa615140a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4f70656e4275696c64696e67732f6a616d2d6d6f6e65746172792f6261646765732f7175616c6974792d73636f72652e706e673f733d36313934663964653131616330386438393865623437663162623866643536633563643231396333)](https://scrutinizer-ci.com/g/OpenBuildings/jam-monetary/)[![Code Coverage](https://camo.githubusercontent.com/e0500e58324f83b1a0f53dc849923d2509f77de6d5d2d2440faddabe0dfd3520/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4f70656e4275696c64696e67732f6a616d2d6d6f6e65746172792f6261646765732f636f7665726167652e706e673f733d38323931363333343738343465366534393066353165623332623930636234366239656566636537)](https://scrutinizer-ci.com/g/OpenBuildings/jam-monetary/)[![Latest Stable Version](https://camo.githubusercontent.com/9cdd0a79b1d7c00b66258364a2f96de424bb27ee2407aceb5f1536378f776532/68747470733a2f2f706f7365722e707567782e6f72672f6f70656e6275696c64696e67732f6a616d2d6d6f6e65746172792f762f737461626c652e706e67)](https://packagist.org/packages/openbuildings/jam-monetary)

Usage
-----

[](#usage)

In your model, define the field as usual:

```
class Model_Product extends Jam_Model {

	static public function initialize(Jam_Meta $meta)
	{
		$meta
			->fields(array(
				'id' => Jam::field('primary'),
				'name' => Jam::field('string'),
				'price' => Jam::field('price', array('default_currency' => 'GBP')),
				'discount_price' => Jam::field('price'),
			));
	}
}
```

And to use it you can:

```
$product = Jam::build('product', array('price' => 10));

echo $product->price->amount();         // will output 10.00 float
echo $product->price->currency();       // will output GBP - the price currency
echo $product->price;                   // will output '10.00'
echo $product->price->as_string();      // will output '10.00'
echo $product->price->as_string('USD'); // will output '10.00'
echo $product->price->in('USD');        // will output 18.12 float
echo $product->price->humanize();       // will output '£10.00'
echo $product->price->humanize('USD');  // will output '$18.12'
echo $product->price->as_html();        // will output '&pound;10.00'
echo $product->price->as_html('USD');   // will output '$18.12'
echo $product->price->as_html('EUR');   // will output '&euro;18.12'

// Price arithmetic
$product->price->add(10);

// Add 2 prices together, doing the exchange conversion arithmetic on the fly
$product->price->add(new Jam_Price(20, 'EUR'));

// Adding more than one price
$product->price->add(new Jam_Price(20, 'EUR'), new Jam_Price(10, 'GBP'), 12.32);
```

Methods
-------

[](#methods)

- `in($currency)` : display the amount in the specified currency, put through number\_format with 2 digits after the dot
- `as_string($currency = NULL)` : return the number\_format() on the price's amount, with 2 digits after the dot.
- `humanize($currency = NULL)` : display the amount with showing the proper currency sign in the correct position
- `as_html($currency = NULL)` : same as `humanize()`, but with HTML entities support
- `add(... prices)` : add one or more price values to this price (you can add negative prices in order to substract)

Automatic currency and monetary values
--------------------------------------

[](#automatic-currency-and-monetary-values)

If the model has a method `currency()`, then each time a price object is requested, the result of this method is used for the price currency. That will allow you storing the currency alongside the amount iteself in the model

The same goes for a `monetary()` method - if its there in the model, then it'll be used for all the conversions.

Validators
----------

[](#validators)

There are 2 out of the box validator rules - one for currency and one for price.

The price rule is basically a numeric rule, which performes the checks on the price's amount.

The currency validator is a choice validator, with the currencies of the world preselected in the "in" variable.

```
class Model_Product extends Jam_Model {

	static public function initialize(Jam_Meta $meta)
	{
		$meta
			->fields(array(
				'id' => Jam::field('primary'),
				'price' => Jam::field('price'),
				'currency' => Jam::field('string'),
			))
			->validator('price' => array('price' => array('greater_than' => 10)))
			->validator('currency' => array('currency' => TRUE));
	}
}
```

License
-------

[](#license)

Copyright (c) 2012-2013, OpenBuildings Ltd. Developed by Ivan Kerin as part of [clippings.com](https://clippings.com)

Under BSD-3-Clause license, read [LICENSE file](LICENSE).

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~91 days

Recently: every ~229 days

Total

27

Last Release

2258d ago

PHP version history (3 changes)0.1.0PHP &gt;=5.3.0

0.1.23PHP &gt;=5.4.0

0.2.0PHP ^7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/506129?v=4)[Harry Dobrev](/maintainers/hkdobrev)[@hkdobrev](https://github.com/hkdobrev)

![](https://avatars.githubusercontent.com/u/4113307?v=4)[Danail Kyosev](/maintainers/dkyosev)[@dkyosev](https://github.com/dkyosev)

![](https://avatars.githubusercontent.com/u/7592650?v=4)[Evstati Zarkov](/maintainers/EZarkov)[@EZarkov](https://github.com/EZarkov)

![](https://avatars.githubusercontent.com/u/745771?v=4)[Filip Georgiev](/maintainers/phgeorgiev)[@phgeorgiev](https://github.com/phgeorgiev)

![](https://avatars.githubusercontent.com/u/490439?v=4)[Zdravko Evstatiev](/maintainers/zedevs)[@zedevs](https://github.com/zedevs)

---

Top Contributors

[![hkdobrev](https://avatars.githubusercontent.com/u/506129?v=4)](https://github.com/hkdobrev "hkdobrev (13 commits)")[![ivank](https://avatars.githubusercontent.com/u/4976?v=4)](https://github.com/ivank "ivank (8 commits)")[![EZarkov](https://avatars.githubusercontent.com/u/7592650?v=4)](https://github.com/EZarkov "EZarkov (5 commits)")[![tumbalev](https://avatars.githubusercontent.com/u/28398671?v=4)](https://github.com/tumbalev "tumbalev (5 commits)")[![dkyosev](https://avatars.githubusercontent.com/u/4113307?v=4)](https://github.com/dkyosev "dkyosev (2 commits)")[![bozhidargyurov](https://avatars.githubusercontent.com/u/36644891?v=4)](https://github.com/bozhidargyurov "bozhidargyurov (2 commits)")[![sstoyanov7](https://avatars.githubusercontent.com/u/9350596?v=4)](https://github.com/sstoyanov7 "sstoyanov7 (1 commits)")

---

Tags

moneykohanaexchangepricemonetaryjam

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/openbuildings-jam-monetary/health.svg)

```
[![Health](https://phpackages.com/badges/openbuildings-jam-monetary/health.svg)](https://phpackages.com/packages/openbuildings-jam-monetary)
```

###  Alternatives

[ccxt/ccxt

A cryptocurrency trading API with more than 100 exchanges in JavaScript / TypeScript / Python / C# / PHP / Go

41.5k328.9k1](/packages/ccxt-ccxt)[florianv/swap-bundle

Integrates the Swap library with Symfony

62416.1k1](/packages/florianv-swap-bundle)[openbuildings/monetary

Useful tool for formatting and converting currencies

10207.6k1](/packages/openbuildings-monetary)[maciej-sz/nbp-php

API for accessing Polish National Bank (NBP - Narodowy Bank Polski) currency and commodities exchange rates

1343.3k1](/packages/maciej-sz-nbp-php)

PHPackages © 2026

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