2017 © Pedro Peláez
 

library hack-money

A Hack Library for dealing with money and currency conversion.

image

apoyan/hack-money

A Hack Library for dealing with money and currency conversion.

  • Tuesday, March 21, 2017
  • by apoyan
  • Repository
  • 1 Watchers
  • 1 Stars
  • 7 Installations
  • Hack
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Hack Money

A Hack Library for dealing with money and currency conversion, (*1)

Latest Stable Version Total Downloads Latest Unstable Version License, (*2)

Installation

Hack Money is installed via Composer. To install, simply add it to your composer.json file:, (*3)

{
    "require": {
        "apoyan/hack-money": "~1.0"
    }
}

And run composer to update your dependencies:, (*4)

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update

Usage


<?php use Money\Money as Money; # Money $currency = new Currency('USD'); $money = new Money(10.00, $currency); $money_2 = new Money('10.00', $currency); $money = new Money(10, "EUR"); $money = new Money(10.00, "USD"); $money->getAmount(); // => 10.00 $money->getCurrency(); // => "USD" # Comparisons $money->equals($money_2); // => false $money->equals($money); // => true $money->isSameCurrency($money_2); // => true # Arithmetic $money->add($money_2)->getAmount(); // => "110.00" $money->sub(new Money(10, "USD"))->getAmount(); // => "10.00" $money->div(new Money(10, "EUR"))->getAmount(); // => "Exception: Currencies must be identical" $money->mul(new Money(2, "USD"))->getAmount(); // => "20.00" # Formatting $currency = new Currency('USD'); $money = new Money("1000000.00", $currency); $money->format( [ "with_currency" => true, "no_cents_if_whole" => true, "thousands_separator" => ' ', "decimal_mark" => ',', "with_symbol" => true, "symbol_position" => "before" ] ); // => "$1 000 000 USD"

Currency

``` php <?php $currency = new Currency('USD'); $currency_2 = new Currency('EUR'); $currency_3 = new Currency('USD');, (*5)

$currency->getCode(); // => "USD" $currency->getName(); // => "United States Dollar" $currency->getSymbol(); // => "$" $currency->exponent(); // => 2, (*6)

$currency->equals($currency_2); // => false $currency->equals($currency_3); // => true $currency->equals("USD"); // => true, (*7)

```, (*8)

The Versions

21/03 2017

dev-master

9999999-dev https://github.com/apoyan/hack-money

A Hack Library for dealing with money and currency conversion.

  Sources   Download

MIT

money value object vo