
Represents a monetary value - USD are supported by default and others can be added via defineCurrency()
1.0.0b3 | Added the $remove_zero_fraction parameter to format() 6/9/10 |
---|---|
1.0.0b2 | Fixed a bug with calling format() when a format callback is set, fixed NULL $element handling in getCurrencyInfo() 3/24/09 |
1.0.0b | The initial implementation 8/10/08 |
Allows adding a new currency, or modifying an existing one
void defineCurrency( string $iso_code, string $name, string $symbol, integer $precision, string $value )
string | $iso_code | The ISO code (three letters, e.g. 'USD') for the currency |
string | $name | The name of the currency |
string | $symbol | The symbol for the currency |
integer | $precision | The number of digits after the decimal separator to store |
string | $value | The value of the currency relative to some common standard between all currencies |
Lists all of the defined currencies
array getCurrencies( )
The 3 letter ISO codes for all of the defined currencies
Allows retrieving information about a currency
mixed getCurrencyInfo( string $iso_code, string $element=NULL )
string | $iso_code | The ISO code (three letters, e.g. 'USD') for the currency |
string | $element | The element to retrieve: 'name', 'symbol', 'precision', 'value' |
An associative array of the currency info, or the element specified
Gets the default currency
string getDefaultCurrency( )
The ISO code of the default currency
Allows setting a callback to translate or modify any return values from format()
void registerFormatCallback( callback $callback )
Allows setting a callback to clean any formatted values so they can be passed to fNumber
void registerUnformatCallback( callback $callback )
callback | $callback | The callback to pass formatted strings to. Should accept a formatted string and a currency code and return a string suitable to passing to the fNumber constructor. |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Resets the configuration of the class
void reset( )
Sets the default currency to use when creating fMoney objects
void setDefaultCurrency( string $iso_code )
string | $iso_code | The ISO code (three letters, e.g. 'USD') for the new default currency |
Creates the monetary to represent, with an optional currency
fMoney __construct( fNumber|string $amount, string $currency=NULL )
fNumber|string | $amount | The monetary value to represent, should never be a float since those are imprecise |
string | $currency | The currency ISO code (three letters, e.g. 'USD') for this value |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
All requests that hit this method should be requests for callbacks
callback __get( string $method )
string | $method | The method to create a callback for |
The callback for the method requested
Returns the monetary value without a currency symbol or thousand separator (e.g. 2000.12)
string __toString( )
The monetary value without currency symbol or thousands separator
Adds the passed monetary value to the current one
fMoney add( fMoney|string|integer $addend )
fMoney|string|integer | $addend | The money object to add - a string or integer will be converted to the default currency (if defined) |
The sum of the monetary values in this currency
Splits the current value into multiple parts ensuring that the sum of the results is exactly equal to this amount
This method takes two or more parameters. The parameters should each be fractions that when added together equal 1.
array allocate( fNumber|string $ratio1, fNumber|string $ratio2, fNumber|string ... )
fNumber|string | $ratio1 | The ratio of the first amount to this amount |
fNumber|string | $ratio2 [, ... ] | The ratio of the second amount to this amount |
fMoney objects each with the appropriate ratio of the current amount
Converts this money amount to another currency
fMoney convert( string $new_currency )
string | $new_currency | The ISO code (three letters, e.g. 'USD') for the new currency |
A new fMoney object representing this amount in the new currency
Checks to see if two monetary values are equal
boolean eq( fMoney|string|integer $money )
fMoney|string|integer | $money | The money object to compare to - a string or integer will be converted to the default currency (if defined) |
If the monetary values are equal
Formats the amount by preceeding the amount with the currency symbol and adding thousands separators
string format( boolean $remove_zero_fraction=FALSE )
boolean | $remove_zero_fraction | If TRUE and all digits after the decimal place are 0, the decimal place and all zeros are removed |
The formatted (and possibly converted) value
Returns the fNumber object representing the amount
fNumber getAmount( )
The amount of this monetary value
Returns the currency ISO code
string getCurrency( )
The currency ISO code (three letters, e.g. 'USD')
Checks to see if this value is greater than the one passed
boolean gt( fMoney|string|integer $money )
fMoney|string|integer | $money | The money object to compare to - a string or integer will be converted to the default currency (if defined) |
If this value is greater than the one passed
Checks to see if this value is greater than or equal to the one passed
boolean gte( fMoney|string|integer $money )
fMoney|string|integer | $money | The money object to compare to - a string or integer will be converted to the default currency (if defined) |
If this value is greater than or equal to the one passed
Checks to see if this value is less than the one passed
boolean lt( fMoney|string|integer $money )
fMoney|string|integer | $money | The money object to compare to - a string or integer will be converted to the default currency (if defined) |
If this value is less than the one passed
Checks to see if this value is less than or equal to the one passed
boolean lte( fMoney|string|integer $money )
fMoney|string|integer | $money | The money object to compare to - a string or integer will be converted to the default currency (if defined) |
If this value is less than or equal to the one passed
Mupltiplies this monetary value times the number passed
fMoney mul( fNumber|string|integer $multiplicand )
fNumber|string|integer | $multiplicand | The number of times to multiply this ammount - don't use a float since they are imprecise |
The product of the monetary value and the multiplicand passed
Subtracts the passed monetary value from the current one
fMoney sub( fMoney|string|integer $subtrahend )
fMoney|string|integer | $subtrahend | The money object to subtract - a string or integer will be converted to the default currency (if defined) |
The difference of the monetary values in this currency