本文整理汇总了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());
}