2017 © Pedro PelĂĄez
 

library money

A simple and cross-platform alternative to PHP money_format(). 91 currencies supported, including INR.

image

gerardojbaez/money

A simple and cross-platform alternative to PHP money_format(). 91 currencies supported, including INR.

  • Saturday, February 24, 2018
  • by gerardojbaez
  • Repository
  • 3 Watchers
  • 15 Stars
  • 2,664 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 7 Forks
  • 1 Open issues
  • 9 Versions
  • 51 % Grown

The README.md

Money

Money is a small PHP library that helps you format numbers to currencies, including INR (Indian Rupee) and NGN (Nigrian Naira). It's a simple alternative to money_format()., (*1)

Example:, (*2)

<?php

$money = new Gerardojbaez\Money\Money(12.99, 'USD')
$money->format(); // RESULT: $12.99

// You can also use the included helper:
moneyFormat(12.99, 'USD'); // RESULT: $12.99

Content

Installation

Pull this package through Composer (file composer.json), (*3)

{
    "require": {
        "gerardojbaez/money": "0.*"
    }
}

Then run, (*4)

composer update
<?php

require 'vendor/autoload.php';

use Gerardojbaez\Money\Money;

$money = new Money(100);
$money->format();

Basic Usage

Currencies Supported

ARS, AMD, AWG, AUD, BSD, BHD, BDT, BZD, BMD, BOB, BAM, BWP, BRL, BND, CAD, KYD, CLP, CNY, COP, CRC, HRK, CUC, CUP, CYP, CZK, DKK, DOP, XCD, EGP, SVC, EUR, GHC, GIP, GTQ, HNL, HKD, HUF, ISK, INR, IDR, IRR, JMD, JPY, JOD, KES, KWD, LVL, LBP, LTL, MKD, MYR, MTL, MUR, MXN, MZM, NPR, ANG, ILS, TRY, NZD, NOK, PKR, PEN, UYU, PHP, PLN, GBP, OMR, RON, ROL, RUB, SAR, SGD, SKK, SIT, ZAR, KRW, SZL, SEK, CHF, TZS, THB, TOP, AED, UAH, USD, VUV, VEF, VEB, VND, ZWD., (*5)

Formatting Using Helper Function

<?php

// USD
echo moneyFormat(100); // RESULT: $100.00
echo moneyFormat(10000); // RESULT: $10,000.00

// INR
echo moneyFormat(100, 'INR'); // RESULT: à€°100
echo moneyFormat(1000000, 'INR'); // RESULT: à€°10,00,000

Formatting Using Class

<?php

$money = new Gerardojbaez\Money\Money(1000000, 'INR');

echo $money->format(); // RESULT: à€°10,00,000
echo $money; // The same as using $money->format()

echo $money->amount(); // RESULT: 10,00,000

Customizing Currency Format

To use a custom format, create an instance of the Currency class with the desired currency and use the setters (se the example below) to apply the desired format. Use this instance with the Money class (or the helper) to finally format the number., (*6)

For example:, (*7)

$currency = new Gerardojbaez\Money\Currency('USD');
$currency->setPrecision(3);
$currency->setThousandSeparator('.');
$currency->setDecimalSeparator(',');
$currency->setSymbolPlacement('after');

$money = new Gerardojbaez\Money\Money(1200.9, $currency);
echo $money; // RESULT: 1.200,900$ (example)

// OR
echo moneyFormat(1200.9, $currency);

Parse String

<?php

echo Money::parse('$1,200.90', 'USD')->toDecimal(); // RESULT: 1200.9

Get Currency Information


$currency = new Gerardojbaez\Money\Currency('USD'); echo $currency->getTitle(); // US Dollar echo $currency->getCode(); // USD echo $currency->getSymbol(); // $ echo $currency->getSymbolPlacement(); // after (before|after amount) echo $currency->getPrecision(); // 2 (number of decimals) echo $currency->getThousandSeparator(); // , echo $currency->getDecimalSeparator(); // .

Get All Supported Currencies


$currencies = Gerardojbaez\Money\Currency::getAllCurrencies(); // Result Example: [ 'ARS' => [ 'code' => 'ARS' 'title' => 'Argentine Peso' 'symbol' => null 'precision' => 2 'thousandSeparator' => ',' 'decimalSeparator' => '.' 'symbolPlacement' => 'before' ] 'AMD' => [ 'code' => 'AMD' 'title' => 'Armenian Dram' 'symbol' => null 'precision' => 2 'thousandSeparator' => '.' 'decimalSeparator' => ',' 'symbolPlacement' => 'before' ] ...

License

This package is free software distributed under the terms of the MIT license., (*8)

The Versions

24/02 2018

dev-master

9999999-dev

A simple and cross-platform alternative to PHP money_format(). 91 currencies supported, including INR.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Gerardo BĂĄez

formatter currency money money_format

24/02 2018

v0.3.1

0.3.1.0

A simple and cross-platform alternative to PHP money_format(). 91 currencies supported, including INR.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Gerardo BĂĄez

formatter currency money money_format

29/10 2016

v0.3.0

0.3.0.0

A simple and cross-platform alternative to PHP money_format(). 91 currencies supported, including INR.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Gerardo BĂĄez

formatter currency money money_format

17/09 2016

v0.2.1

0.2.1.0

A simple and cross-platform alternative to PHP money_format(). 91 currencies supported, including INR.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Gerardo BĂĄez

formatter currency money money_format

03/08 2016

v0.2.0

0.2.0.0

A simple and cross-platform alternative to PHP money_format(). 91 currencies supported, including INR.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Gerardo BĂĄez

formatter currency money money_format

30/07 2016

v0.1.2

0.1.2.0

A simple and cross-platform alternative to PHP money_format(). 91 currencies supported, including INR.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

by Gerardo BĂĄez

formatter currency money money_format

30/07 2016

v0.1.1

0.1.1.0

A simple and cross-platform alternative to PHP money_format(). 91 currencies supported, including INR.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

by Gerardo BĂĄez

formatter currency money money_format

25/07 2016

v0.1.0

0.1.0.0

A simple and cross-platform alternative to PHP money_format(). 91 currencies supported, including INR.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

by Gerardo BĂĄez

formatter currency money money_format

25/07 2016

v0.0.1

0.0.1.0

A simple and cross-platform alternative to PHP money_format(). 91 currencies supported, including INR.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

by Gerardo BĂĄez

formatter currency money money_format