Methods
-
getInfo
Returns information about a currency, as an array, by its ISO3 code.
-
format
Returns formatted amount value with currency; e.g., "$125,000.00".
-
formatWithUnit
Returns a short notation of a large number.
-
getAll
Returns the list of all currencies available in the framework.
-
round
Returns a rounded numeric value.
public static function getInfo ($currency)
Returns information about a currency by its ISO3 code, which is retrieved from its config file located in wa-system/currency/data/
.
Parameters
-
$currency
Currency's ISO3 code.
Example
waCurrency::getInfo ('USD')
Result
[ [code] => USD [sign] => $ [sign_position] => 0 [sign_delim] => [title] => United States Dollar [name] => [ [0] => [ [0] => dollar [1] => dollars ] [1] => US$ ] [frac_name] => [ [0] => [ [0] => cent [1] => cents ] ] ]
public static function format ($format, $n, $currency, $locale = null)
Returns formatted amount value with currency.
Parameters
-
$format
Amount format. The format string must begin with % character and may contain the following optional parts in the specified order:
- Precision (number of digits after decimal separator) expressed as an arbitrary integer value. If not specified, then 2 decinal digits are displayed by default.
- Display type (as a number; e.g., "123456", or in words; e.g., 'one hundred and twenty-three thousand four hundred and fifty-six"). To use the numerical format, specify i; for verbal format, use w. The verbal expression of a number contains its integer part only, the decimal part is ignored. If the display type is not specified, then the numerical format is used by default.
- Currency sign or name. To add it to the formatted amount value, specify one of the following identifiers in curly brackets:
{n}
: full cyrrency name; e.g., "dollar"{s}
: brief currency name or sign; e.g., "$"{h}
: currency's HTML sign; of the currency has HTML sign, then format's'
is used by default{f}
: name of the fractional currency unit; e.g., "cent/cents"{c}
: currency code; e.g., "USD".
-
$n
Original number.
-
$currency
Currency's ISO3 code.
-
$locale
Locale ID; e.g.,
ru_RU
oren_US
.
Example
waCurrency::format ('%0{s}', 123456.78, 'USD', 'en_US')
Result
$123,457
Example
waCurrency::format ('%w{n}', 123456.78, 'USD', 'en_US')
Result
one hundred and twenty-three thousand four hundred and fifty-six dollars
PHP functions
wa_currency ($n, $currency, $format = '%{s}')
Wrapper for method format using current user's locale.
Example
wa_currency (123465, 'USD')
Result
$123 465
wa_currency_html ($n, $currency, $format = '%{h}')
Wrapper for method format used for embedding formatted amount values in HTML code using current user's locale (for currencies having a value for sign_html
parameter specified in its config file located in
wa-system/currency/data/
).
Smarty modifiers
{$amount |wa_format_amount_currency [:$currency_id=null, $locale=null]}
Formats a number as an amount expressed in a currency using the format method. Format string '%{s}'
is used.
Example
{'123456'|wa_format_amount_currency:'USD'}
Result
$123 456
{$amount |wa_format_amount_currency_words [:$currency_id=null, $locale=null]}
Formats a number as an amount expressed in a currency using the format method. Format string '%.W{n0} %.2{f0}'
is used by default.
Example
{'123456'|wa_format_amount_currency_words:'USD':'en_US'}
Result
One hundred and twenty-three thousand four hundred and fifty-six dollars 00 cents
public static function formatWithUnit ($total, $locale = null)
Returns a short notation of a large number. For example, 1.23M instead of 1234578.
Parameters
-
$total
The number which must be written in a short form.
-
$locale
ID of the locale for which the returned result must be formatted. If no value is specified then the current user locale is taken into account.
Пример
waCurrency::formatWithUnit(1234578);
Результат
1,23M
public static function getAll ($type = 'title')
Returns the list of all available currencies.
Parameters
-
$type
Currency data item id specified in configuration file in
wa-system/currency/data/
:all
: this value, or its alternative formtrue
, returns all currency data itemscode
: currency ISO3 codesign
: currency symboltitle
: currency name
Example
waCurrency::getAll ('sign')
Result
[ [JPY] => ¥ [CLP] => $ [TRY] => TL [VEF] => Bs.F. [BSD] => $ [LTL] => Lt ... [GYD] => $ [USD] => $ [NPR] => Rs. [BZD] => $ [PHP] => P [BBD] => Bds$ ]
public static function round ($n, $currency)
Returns a rounded numeric value.
Parameters
-
$n
The number which must be rounded.
-
$currency
Information about the number of decimal signs, to which the original number must be rounded, in one of the following formats:
- currency ID — the number of decimal signs will be extracted from the
'precision'
in the currency configuration; - currency configuration array with the
'precision'
containing the number of decimal signs; - integer denoting the number of decimal signs.
- currency ID — the number of decimal signs will be extracted from the
Example
waCurrency::round(123.4567, 'USD');
Result
123.46
Example
waCurrency::round(123.4567, 3);
Result
123.457