Download the PHP package sebastian/money without Composer
On this page you can find all versions of the php package sebastian/money. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sebastian/money
More information about sebastian/money
Files in sebastian/money
Package money
Short Description Value Object that represents a monetary value (using a currency's smallest unit)
License BSD-3-Clause
Homepage http://www.github.com/sebastianbergmann/money
Informations about the package money
This project has been abandoned. It was only ever intended to be used as an example for PHPUnit features etc. and not for usage in production. I am sorry that I failed to make that clear. Please have a look at moneyphp/money instead.
Money
Value Object that represents a monetary value using a currency's smallest unit.
Installation
Simply add a dependency on sebastian/money
to your project's composer.json
file if you use Composer to manage the dependencies of your project.
Here is a minimal example of a composer.json
file that just defines a dependency on Money:
{
"require": {
"sebastian/money": "^1.6"
}
}
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
Using a Currency-specific subclass of Money
The code above produces the output shown below:
100
Please note that there is no subclass of Money
that is specific to Turkish Lira as TRY
is not a valid class name in PHP.
Formatting a Money object using PHP's built-in NumberFormatter
The code above produces the output shown below:
1,00 €
Basic arithmetic using Money objects
The code above produces the output shown below:
-100
300
100
200
Comparing Money objects
The code above produces the output shown below:
bool(true)
bool(false)
bool(false)
bool(true)
int(-1)
int(0)
int(1)
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.
All versions of money with dependencies
ext-intl Version *