waCurrency

Processing of currency-related data

Contents...

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".

  • getAll

    Returns the list of all currencies available in the framework.

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

Array
(
    [code] => USD
    [sign] => $
    [sign_position] => 0
    [sign_delim] => 
    [title] => United States Dollar
    [name] => Array
        (
            [0] => Array
                (
                    [0] => dollar
                    [1] => dollars
                )

            [1] => US$
        )

    [frac_name] => Array
        (
            [0] => Array
                (
                    [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:

    1. Precision (number of digits after decimal separator) expressed as an arbitrary integer value. If not specified, then 2 decinal digits are displayed by default.
    2. 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.
    3. 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 or en_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 getAll ($type = 'title')

Returns the list of all available currencies.

Parameters

  • $type

    Currency data item id specified in cofiguration file in wa-system/currency/data/:

    • all: this value, or its alternative form true, returns all currency data items
    • code: currency ISO3 code
    • sign: currency symbol
    • title: currency name

Example

waCurrency::getAll ('sign')

Result

Array
(
    [JPY] => ¥
    [CLP] => $
    [TRY] => TL
    [VEF] => Bs.F.
    [BSD] => $
    [LTL] => Lt
    ...
    [GYD] => $
    [USD] => $
    [NPR] => Rs.
    [BZD] => $
    [PHP] => P
    [BBD] => Bds$
)