Documentation

GetCurrencyFormat

array
CCurrencyLang::GetCurrencyFormat(
 string currency, 
 string lang = LANGUAGE_ID
);

The method returns array of language-dependent currency parameters for 'lang'.

Similar to the method CCurrencyLang::GetByID with exception that the result returned via CCurrencyLang::GetCurrencyFormat is cached. That is why, the repeated method call with the same currency and language codes within the same page does not result in an additional database query. Non-static method.

Method parameters /h4>
Parameter Description
currency Currency ID code which language-dependent parameters are needed.
lang Language ID code. Optional parameter.

Returned values

Associative array with keys:

Key Description
CURRENCY Currency ID code (three-character)
LID Language ID code.
FORMAT_STRING Format string that defines display of currency amounts with this language.
FULL_NAME Full currency name.
DEC_POINT Decimal point character when displaying amounts.
THOUSANDS_SEP Thousand separator.
DECIMALS Number of displayed decimal places.
HIDE_ZERO (Y|N) specifies to hide or show nonsignificant zeros in decimal part (the result will be visible only in public part).

Examples

<?
function MyFormatCurrency($fSum, $strCurrency)
{
    if (!isset($fSum) || strlen($fSum)<=0)
        return "";

    $arCurFormat = CCurrencyLang::GetCurrencyFormat($strCurrency);

    if (!isset($arCurFormat["DECIMALS"]))
        $arCurFormat["DECIMALS"] = 2;

    $arCurFormat["DECIMALS"] = IntVal($arCurFormat["DECIMALS"]);

    if (!isset($arCurFormat["DEC_POINT"]))
        $arCurFormat["DEC_POINT"] = ".";

    if (!isset($arCurFormat["THOUSANDS_SEP"]))
        $arCurFormat["THOUSANDS_SEP"] = "\\"."xA0";

    if (!isset($arCurFormat["FORMAT_STRING"]))
        $arCurFormat["FORMAT_STRING"] = "#";

    $num = number_format($fSum,
                         $arCurFormat["DECIMALS"],
                         $arCurFormat["DEC_POINT"],
                         $arCurFormat["THOUSANDS_SEP"]);

    return str_replace("#",
                       $num,
                       $arCurFormat["FORMAT_STRING"]);
}

echo "The amount 11800.95 USD on the current language will be displayed as follows: ";
echo MyFormatCurrency(11800.95, "USD");
?>


© «Bitrix24», 2001-2024