Download the PHP package rebilly/money without Composer
On this page you can find all versions of the php package rebilly/money. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rebilly/money
More information about rebilly/money
Files in rebilly/money
Package money
Short Description Implementation of the Money Value Object
License MIT
Homepage https://github.com/rebilly/money/
Informations about the package money
Money
Value Object that represents a monetary value using a currency's smallest unit. This library is originally based on Sebastian Bergmann's discontinued library. It's been updated with support added for currency exchange.
Installation
Simply add a dependency on rebilly/money
to your project's composer.json
file if you use Composer to manage the dependencies of your project.
Usage Examples
Creating a Money object and accessing its monetary value
The code above produces the output shown below:
100
1.00
Creating a Money object from a string value
The code above produces the output shown below:
1234
Basic arithmetic using Money objects
The code above produces the output shown below:
-100
300
100
200
The compareTo()
method returns an integer less than, equal to, or greater than
zero if the value of one Money
object is considered to be respectively less
than, equal to, or greater than that of another Money
object.
You can use the compareTo()
method to sort an array of Money
objects using
PHP's built-in sorting functions:
The code above produces the output shown below:
100
200
300
Allocate the monetary value represented by a Money object among N targets
The code above produces the output shown below:
10
10
10
10
10
10
10
10
10
9
Allocate the monetary value represented by a Money object using a list of ratios
The code above produces the output shown below:
2
3
Extract a percentage (and a subtotal) from the monetary value represented by a Money object
The code above produces the output shown below:
10000 = 8265 + 1735
Please note that this extracts the percentage out of a monetary value where the
percentage is already included. If you want to get the percentage of the
monetary value you should use multiplication (multiply(0.21)
, for instance,
to calculate 21% of a monetary value represented by a Money object) instead.
Convert Money object currency to to another Money object given a conversion rate
Convert Money using a Rate Object
Get Currency Exchange Rate Using a Rate Provider
Tests
Security
If you discover a security vulnerability, please report it to security at rebilly dot com.
License
The Money library is open-sourced under the MIT License distributed with the software.
All versions of money with dependencies
ext-json Version *
ext-mbstring Version *