本文整理匯總了PHP中Zend_Currency::getLocale方法的典型用法代碼示例。如果您正苦於以下問題:PHP Zend_Currency::getLocale方法的具體用法?PHP Zend_Currency::getLocale怎麽用?PHP Zend_Currency::getLocale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend_Currency
的用法示例。
在下文中一共展示了Zend_Currency::getLocale方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: parseZendCurrencyFormat
/**
* Parses a Zend_Currency & Zend_Locale into a NostoCurrency object.
*
* REQUIRES Zend Framework (version 1) to be available.
*
* @param string $currencyCode the 3-letter ISO 4217 currency code.
* @param Zend_Currency $zendCurrency the zend currency object.
* @return NostoCurrency the parsed nosto currency object.
*
* @throws NostoInvalidArgumentException
*/
public function parseZendCurrencyFormat($currencyCode, Zend_Currency $zendCurrency)
{
try {
$format = Zend_Locale_Data::getContent($zendCurrency->getLocale(), 'currencynumber');
$symbols = Zend_Locale_Data::getList($zendCurrency->getLocale(), 'symbols');
// Remove extra part, e.g. "¤ #,##0.00; (¤ #,##0.00)" => "¤ #,##0.00".
if (($pos = strpos($format, ';')) !== false) {
$format = substr($format, 0, $pos);
}
// Check if the currency symbol is before or after the amount.
$symbolPosition = strpos(trim($format), '¤') === 0 ? NostoCurrencySymbol::SYMBOL_POS_LEFT : NostoCurrencySymbol::SYMBOL_POS_RIGHT;
// Remove all other characters than "0", "#", "." and ",",
$format = preg_replace('/[^0\\#\\.,]/', '', $format);
// Calculate the decimal precision.
$precision = 0;
if (($decimalPos = strpos($format, '.')) !== false) {
$precision = strlen($format) - (strrpos($format, '.') + 1);
} else {
$decimalPos = strlen($format);
}
$decimalFormat = substr($format, $decimalPos);
if (($pos = strpos($decimalFormat, '#')) !== false) {
$precision = strlen($decimalFormat) - $pos - $precision;
}
// Calculate the group length.
if (strrpos($format, ',') !== false) {
$groupLength = $decimalPos - strrpos($format, ',') - 1;
} else {
$groupLength = strrpos($format, '.');
}
// If the symbol is missing for the current locale, use the ISO code.
$currencySymbol = $zendCurrency->getSymbol();
if (is_null($currencySymbol)) {
$currencySymbol = $currencyCode;
}
return new NostoCurrency(new NostoCurrencyCode($currencyCode), new NostoCurrencySymbol($currencySymbol, $symbolPosition), new NostoCurrencyFormat($symbols['group'], $groupLength, $symbols['decimal'], $precision));
} catch (Zend_Exception $e) {
throw new NostoInvalidArgumentException($e);
}
}
示例2: testValueWithConstructor
/**
* Testing value at initiation
*/
public function testValueWithConstructor()
{
$currency = new Zend_Currency(array('currency' => 'EUR', 'locale' => 'de_AT', 'value' => 100));
$this->assertEquals('de_AT', $currency->getLocale());
$this->assertEquals('EUR', $currency->getShortName());
$this->assertEquals('€ 100,00', $currency->toCurrency());
}