Money
It makes the World go round and so we've dedicated a complete object in its honour with some pretty funky methods to help you with multi-currency theme requirements.
The money object is found throughout Evance, as you would expect with an ecommerce platform. Product prices and cart values are automatically cast as Money objects, but you can instantiate a Money object yourself:
Instantiation
// creating a new Money object
var gbp = new Money(1); // use the current locale's currency
var usd = new Money(1, 'USD'); // explicitly set the currency
// from a number
var num = 1.toMoney();
Constructor parameters |
---|
amount
Number
The decimal value. |
currency
String
(optional)
The currency of your Money object. When omitted the default currency for the current locale is used. |
Methods |
---|
amount()
Number
Returns the exact amount of money (not rounded). |
convertTo(String:isoCode)
Money
Convert to a new Currency and adjust the value using Evance's internal exchange rate. The new Money object will adopt the correct formatting for the new isoCode Currency.
|
currency([String:isoCode])
Money |
Currency
Get or set the current Currency of the Money object. Gets a Currency object if no Sets the currency to the supplied
|
decimal([Number:precision])
String
Returns the decimal value as a new String to preserve decimal places. If precision is not supplied the number of decimal places defaults to the number of decimal places for the currency.
|
format([precision [, decimal [, thousands]]])
String
Allows you to output the Money value in a format of your choice. However, unlike the Number object the default values for precision, decimal and thousands are that of the Currency object and as such all are optional. The format method is also the toString method and therefore only needs to used if you wish to alter the format of the Money when outputting it. Parameters
|
prefix()
String
Alias of |
suffix()
String
Alias of |
symbolLeft()
String
The currency symbol usually placed before the decimal value. |
symbolRight()
String
The currency symbol usually placed after the decimal value. |
toNumber()
Number
Returns a new Number representing the decimal value of the Money. |
toString()
String
Returns a new String representation of Money using all default values for the Money.format() method. |