/** * */ public function getDisplayValue($pa_options = null) { if (caGetOption('returnAsDecimalWithCurrencySpecifier', $pa_options, false)) { return $this->ops_currency_specifier . ' ' . $this->opn_value; } if (Zend_Registry::isRegistered("Zend_Locale")) { $o_locale = Zend_Registry::get('Zend_Locale'); } else { $o_locale = new Zend_Locale('en_US'); } $vs_format = Zend_Locale_Data::getContent($o_locale, 'currencynumber'); // this returns a string like '50,00 ¤' for locale de_DE $vs_decimal_with_placeholder = Zend_Locale_Format::toNumber($this->opn_value, array('locale' => $locale, 'number_format' => $vs_format, 'precision' => 2)); // if the currency placeholder is the first character, for instance in en_US locale ($10), insert a space. // this has to be done because we don't print "$10" (which is expected in the locale rules) but "USD 10" ... and that looks nicer with an additional space. if (substr($vs_decimal_with_placeholder, 0, 2) == '¤') { // for whatever reason '¤' has length 2 $vs_decimal_with_placeholder = str_replace('¤', '¤ ', $vs_decimal_with_placeholder); } // insert currency which is not locale-dependent in our case $vs_val = str_replace('¤', $this->ops_currency_specifier, $vs_decimal_with_placeholder); if (($vs_to_currency = caGetOption('displayCurrencyConversion', $pa_options, false)) && $this->ops_currency_specifier != $vs_to_currency) { $vs_val .= " (" . _t("~%1", caConvertCurrencyValue($this->ops_currency_specifier . ' ' . $this->opn_value, $vs_to_currency)) . ")"; } return $vs_val; }
/** * Formats a given value * @see library/Bvb/Grid/Formatter/Bvb_Grid_Formatter_FormatterInterface::format() */ public function format($value) { if (!is_numeric($value)) { return $value; } return Zend_Locale_Format::toNumber($value, $this->_options); }
/** * */ public function getDisplayValue($pa_options = null) { if (caGetOption('returnAsDecimalWithCurrencySpecifier', $pa_options, false)) { return $this->ops_currency_specifier . ' ' . $this->opn_value; } if (Zend_Registry::isRegistered("Zend_Locale")) { $o_locale = Zend_Registry::get('Zend_Locale'); } else { $o_locale = new Zend_Locale('en_US'); } $vs_format = Zend_Locale_Data::getContent($o_locale, 'currencynumber'); // this returns a string like '50,00 ¤' for locale de_DE $vs_decimal_with_placeholder = Zend_Locale_Format::toNumber($this->opn_value, array('locale' => $o_locale, 'number_format' => $vs_format, 'precision' => 2)); // if the currency placeholder is the first character, for instance in en_US locale ($10), insert a space. // we do this because we don't print "$10" (which is expected in the Zend locale rules) but "USD 10" ... and that looks nicer with an additional space. // we also replace the weird multibyte nonsense Zend uses as placeholder with something more reasonable so that // whatever we output here isn't rejected if thrown into parseValue() again if (substr($vs_decimal_with_placeholder, 0, 2) == "¤") { // '¤' has length 2 $vs_decimal_with_placeholder = str_replace("¤", '% ', $vs_decimal_with_placeholder); } elseif (substr($vs_decimal_with_placeholder, -2) == "¤") { // placeholder at the end $vs_decimal_with_placeholder = preg_replace("![^\\d\\,\\.]!", "", $vs_decimal_with_placeholder) . " %"; } // insert currency which is not locale-dependent in our case $vs_val = str_replace('%', $this->ops_currency_specifier, $vs_decimal_with_placeholder); if (($vs_to_currency = caGetOption('displayCurrencyConversion', $pa_options, false)) && $this->ops_currency_specifier != $vs_to_currency) { $vs_val .= " (" . _t("~%1", caConvertCurrencyValue($this->ops_currency_specifier . ' ' . $this->opn_value, $vs_to_currency)) . ")"; } return $vs_val; }
/** * Returns a number in local specific format. * * @link http://framework.zend.com/manual/de/zend.locale.parsing.html * @param int|float $value * @param array $format * @return mixed */ function smarty_modifier_number($value, $format = array()) { if (empty($format['locale'])) { $format['locale'] = Enlight_Application::Instance()->Locale(); } return Zend_Locale_Format::toNumber($value, $format); }
/** * Converts map array to microdata Object * * @param array $map map array returned by the generator * @return null|Varien_Object */ protected function _createRowObject($map) { if (empty($map['price']) || empty($map['availability']) || empty($map['title'])) { return null; } $microdata = new Varien_Object(); $microdata->setName($map['title']); $microdata->setId($map['id']); if (!empty($map['sale_price'])) { $price = $map['sale_price']; } else { $price = $map['price']; } $microdata->setPrice(Zend_Locale_Format::toNumber($price, array('precision' => 2, 'number_format' => '#0.00'))); $microdata->setCurrency(Mage::app()->getStore()->getCurrentCurrencyCode()); if ($map['availability'] == 'in stock') { $microdata->setAvailability('http://schema.org/InStock'); } else { $microdata->setAvailability('http://schema.org/OutOfStock'); } if (array_key_exists('condition', $map)) { if (strcasecmp('new', $map['condition']) == 0) { $microdata->setCondition('http://schema.org/NewCondition'); } else { if (strcasecmp('used', $map['condition']) == 0) { $microdata->setCondition('http://schema.org/UsedCondition'); } else { if (strcasecmp('refurbished', $map['condition']) == 0) { $microdata->setCondition('http://schema.org/RefurbishedCondition'); } } } } return $microdata; }
public function getAnualPercentageRate($format = true) { $s = Zend_Locale_Format::toNumber($this->_anualPercentageRate, array('precision' => 2)); if ($format) { return $s . '%'; } else { return $s; } }
/** Format a number with grouped thousands and localized decimal point/thousands separator. * @param number $number The number being formatted. * @param int|null $precision [default: null] The wanted precision; if null or not specified the complete localized number will be returned. * @return string * @example http://www.concrete5.org/documentation/how-tos/developers/formatting-numbers/ See the Formatting numbers how-to for more details */ public function format($number, $precision = null) { if (!is_numeric($number)) { return $number; } $options = array('locale' => $this->getZendLocale()); if (is_numeric($precision)) { $options['precision'] = $precision; } return Zend_Locale_Format::toNumber($number, $options); }
public static function number($number, $precision = "", $locale = "") { global $config; $locale == "" ? $locale = new Zend_Locale($config->local->locale) : ($locale = $locale); $load_precision = $config->local->precision; $precision == "" ? $precision = $load_precision : ($precision = $precision); $formatted_number = Zend_Locale_Format::toNumber($number, array('precision' => $precision, 'locale' => $locale)); //trim zeros from decimal point if enabled //if ($config->local->trim_zeros == "y") { $formatted_number = rtrim(trim($formatted_number, '0'), '.'); } return $formatted_number; }
/** * @param mixed $value * @param array $data * * @return $this * * @throws Zend_Locale_Exception */ public function setValue($value, $data = array()) { require_once "Zend/Locale/Format.php"; // If passing in a non-string number, or a value // directly from a DataObject then localise this number if (is_int($value) || is_float($value) || $data instanceof DataObject) { $locale = new Zend_Locale($this->getLocale()); $this->value = Zend_Locale_Format::toNumber($value, array('locale' => $locale)); } else { $this->value = $this->clean($value); } return $this; }
public function __toString() { $value = $this->getValue(); if (is_numeric($value)) { try { $locale = Zend_Registry::get("Zend_Locale"); } catch (Exception $e) { } if ($locale) { $value = Zend_Locale_Format::toNumber($value, array('locale' => $locale)); } } return $value . " " . $this->getUnit()->getAbbreviation(); }
/** * @return string * @throws Zend_Locale_Exception */ public function Value() { if (!$this->isNumeric()) { return '0%'; } require_once "Zend/Locale/Format.php"; $locale = new Zend_Locale($this->getLocale()); // convert from the stored format to a real number so we can multiply $number = Zend_Locale_Format::getNumber($this->clean($this->value), array('locale' => $locale)); $number *= 100.0; // convert back to string $val = Zend_Locale_Format::toNumber($number, array('locale' => $locale)); return $val . '%'; }
/** * returns the value formatet in the current locales currency format * * @return string */ public function Currency($symbol = false) { require_once THIRDPARTY_PATH . "/Zend/Locale/Format.php"; require_once THIRDPARTY_PATH . "/Zend/Currency.php"; if ($this->owner->value) { $locale = new Zend_Locale(i18n::get_locale()); $number = Zend_Locale_Format::toNumber($this->owner->value, array('locale' => $locale)); if ($symbol) { $symbol = new Zend_Currency($locale); $number = $symbol->getSymbol() . " " . $number; } return $number; } }
public function setValue($value, $data = array()) { require_once "Zend/Locale/Format.php"; // If passing in a non-string number, or a value // directly from a dataobject then localise this number if (is_numeric($value) && !is_string($value) || $value && $data instanceof DataObject) { $locale = new Zend_Locale($this->getLocale()); $this->value = Zend_Locale_Format::toNumber($value, array('locale' => $locale)); } else { // If an invalid number, store it anyway, but validate() will fail $this->value = $this->clean($value); } return $this; }
public function getTaxRateIDs($locale = null) { $taxrateDb = new Application_Model_DbTable_Taxrate(); $taxratesObject = $taxrateDb->fetchAll(); $taxrates = array(); if ($locale) { foreach ($taxratesObject as $taxrate) { $taxrates[$taxrate->id] = Zend_Locale_Format::toNumber($taxrate->rate, array('precision' => 1, 'locale' => $locale)) . ' %'; } } else { foreach ($taxratesObject as $taxrate) { $taxrates[$taxrate->id] = $taxrate->rate; } } return $taxrates; }
/** * test to number * expected string */ public function testToNumber() { $this->assertEquals(Zend_Locale_Format::toNumber(0), '0', "string 0 expected"); $this->assertEquals(Zend_Locale_Format::toNumber(0, 'de'), '0', "string 0 expected"); $this->assertEquals(Zend_Locale_Format::toNumber(0, 'de_AT'), '0', "string 0 expected"); $this->assertEquals(Zend_Locale_Format::toNumber(-1234567, 'de_AT'), '-1.234.567', "string -1.234.567 expected"); $this->assertEquals(Zend_Locale_Format::toNumber(1234567, 'de_AT'), '1.234.567', "string 1.234.567 expected"); $this->assertEquals(Zend_Locale_Format::toNumber(0.1234567, 'de_AT'), '0,1234567', "string 0,1234567 expected"); $this->assertEquals(Zend_Locale_Format::toNumber(-1234567.12345, 'de_AT'), '-1.234.567,12345', "string -1.234.567,12345 expected"); $this->assertEquals(Zend_Locale_Format::toNumber(1234567.12345, 'de_AT'), '1.234.567,12345', "value 1.234.567,12345 expected"); $this->assertEquals(Zend_Locale_Format::toNumber(1234567.12345, 'ar_QA'), '1234567٫12345', "value 1234567٫12345 expected"); $this->assertEquals(Zend_Locale_Format::toNumber(-1234567.12345, 'ar_QA'), '1234567٫12345-', "value 1234567٫12345- expected"); $this->assertEquals(Zend_Locale_Format::toNumber(1234567.12345, 'dz_BT'), '12,34,567.12345', "value 12,34,567.12345 expected"); $this->assertEquals(Zend_Locale_Format::toNumber(-1234567.12345, 'mk_MK'), '-(1.234.567,12345)', "value -(1.234.567,12345) expected"); $this->assertEquals(Zend_Locale_Format::toNumber(452.25, 'en_US'), '452.25', "value 452.25 expected"); $this->assertEquals(Zend_Locale_Format::toNumber(54321.1234, 'en_US'), '54,321.1234', "value 54,321.1234 expected"); }
public function indexAction() { $this->_helper->getHelper('layout')->disableLayout(); $processid = $this->_getParam('processid', 0); $locale = Zend_Registry::get('Zend_Locale'); //Get process $processDb = new Processes_Model_DbTable_Process(); $process = $processDb->getProcess($processid); //Get positions $positions = $this->getPositions($processid); //Get units of measurements $uoms = $this->_helper->Uom->getUoms(); $uoms = array_combine($uoms, $uoms); //Get shipping methods $shippingmethods = $this->_helper->ShippingMethod->getShippingMethods($this->_user['clientid']); $forms = array(); $orderings = array(); foreach ($positions as $position) { $orderings[$position->ordering] = $position->ordering; } foreach ($positions as $position) { $position->price = $this->_currency->toCurrency($position->price); $position->supplierinvoicetotal = $this->_currency->toCurrency($position->supplierinvoicetotal); $position->quantity = Zend_Locale_Format::toNumber($position->quantity, array('precision' => 2, 'locale' => $locale)); $form = new Processes_Form_Processpos(); $forms[$position->id] = $form->populate($position->toArray()); $forms[$position->id]->uom->addMultiOptions($uoms); $forms[$position->id]->ordering->addMultiOptions($orderings); $forms[$position->id]->shippingmethod->addMultiOptions($shippingmethods); foreach ($forms[$position->id] as $element) { $id = $element->getId(); $forms[$position->id]->{$id}->setAttrib('id', $id . $position->id); if (!$process['editpositionsseparately']) { $element->setAttrib('disabled', 'disabled'); } } } $this->view->forms = $forms; $this->view->toolbar = new Processes_Form_ToolbarPositions(); }
public function indexAction() { $this->_helper->getHelper('layout')->disableLayout(); $quoteid = $this->_getParam('quoteid', 0); $locale = Zend_Registry::get('Zend_Locale'); //Get quote $quoteDb = new Sales_Model_DbTable_Quote(); $quote = $quoteDb->getQuote($quoteid); //Get positions $positions = $this->getPositions($quoteid); //Get units of measurements $uoms = $this->_helper->Uom->getUoms(); $uoms = array_combine($uoms, $uoms); //Get tax rates $taxRates = $this->_helper->TaxRate->getTaxRates($locale); $forms = array(); $orderings = array(); foreach ($positions as $position) { $orderings[$position->ordering] = $position->ordering; } foreach ($positions as $position) { $position->total = $this->_currency->toCurrency($position->price * $position->quantity); $position->price = $this->_currency->toCurrency($position->price); $position->quantity = Zend_Locale_Format::toNumber($position->quantity, array('precision' => 2, 'locale' => $locale)); $form = new Sales_Form_Quotepos(); $forms[$position->id] = $form->populate($position->toArray()); $forms[$position->id]->uom->addMultiOptions($uoms); $forms[$position->id]->taxrate->addMultiOptions($taxRates); $forms[$position->id]->ordering->addMultiOptions($orderings); } $quote['subtotal'] = $this->_currency->toCurrency($quote['subtotal']); $quote['taxes'] = $this->_currency->toCurrency($quote['taxes']); $quote['total'] = $this->_currency->toCurrency($quote['total']); $this->view->forms = $forms; $this->view->quote = $quote; $this->view->toolbar = new Sales_Form_ToolbarPositions(); }
/** * Return an array of functions used to process the value * * @param string $name The real name and not e.g. the key id * @return array */ protected function _compile($name) { $output = array(); if ($this->model->has($name, 'multiOptions')) { $options = $this->model->get($name, 'multiOptions'); $output['multiOptions'] = function ($value) use($options) { return is_scalar($value) && array_key_exists($value, $options) ? $options[$value] : $value; }; } if ($this->model->has($name, 'formatFunction')) { $output['formatFunction'] = $this->model->get($name, 'formatFunction'); } elseif ($this->model->has($name, 'dateFormat')) { $format = $this->model->get($name, 'dateFormat'); if (is_callable($format)) { $output['dateFormat'] = $format; } else { $storageFormat = $this->model->get($name, 'storageFormat'); $output['dateFormat'] = function ($value) use($format, $storageFormat) { return \MUtil_Date::format($value, $format, $storageFormat); }; } } elseif ($this->model->has($name, 'numberFormat')) { $format = $this->model->get($name, 'numberFormat'); if (is_callable($format)) { $output['numberFormat'] = $format; } else { $output['numberFormat'] = function ($value) use($format) { return \Zend_Locale_Format::toNumber($value, array('number_format' => $format)); }; } } if ($this->model->has($name, 'markCallback')) { $output['markCallback'] = $this->model->get($name, 'markCallback'); } return $output; }
public function formatNumber($value, $precision = null) { $options = array('locale' => Mage::app()->getLocale()->getLocaleCode()); if ($precision) { $options['precision'] = $precision; } return Zend_Locale_Format::toNumber($value, $options); }
public function downloadAction() { $this->_helper->getHelper('layout')->disableLayout(); $this->_helper->viewRenderer->setRender('pdf'); $id = $this->_getParam('id', 0); $locale = Zend_Registry::get('Zend_Locale'); $quoteDb = new Sales_Model_DbTable_Quote(); $quote = $quoteDb->getQuote($id); if ($quote['templateid']) { $templateDb = new Application_Model_DbTable_Template(); $template = $templateDb->getTemplate($quote['templateid']); if ($template['filename']) { $this->_helper->viewRenderer->setRender($template['filename']); } $this->view->template = $template; } $positions = $this->getPositions($id); if (count($positions)) { foreach ($positions as $position) { $precision = floor($position->quantity) == $position->quantity ? 0 : 2; $position->total = $this->_currency->toCurrency($position->price * $position->quantity); $position->price = $this->_currency->toCurrency($position->price); $position->quantity = Zend_Locale_Format::toNumber($position->quantity, array('precision' => $precision, 'locale' => Zend_Registry::get('Zend_Locale'))); } $quote['taxes'] = $this->_currency->toCurrency($quote['taxes']); $quote['subtotal'] = $this->_currency->toCurrency($quote['subtotal']); $quote['total'] = $this->_currency->toCurrency($quote['total']); if ($quote['taxfree']) { $quote['taxrate'] = Zend_Locale_Format::toNumber(0, array('precision' => 2, 'locale' => $locale)); } else { $quote['taxrate'] = Zend_Locale_Format::toNumber($positions[0]->taxrate, array('precision' => 2, 'locale' => $locale)); } } $this->view->quote = $quote; $this->view->positions = $positions; $this->view->footers = $this->_helper->Footer->getFooters($quote['templateid'], $this->_user['clientid']); }
/** * Returns a localized currency string * * @param int|float $value Currency value * @param string $script OPTIONAL Number script to use for output * @param string|Zend_Locale $locale OPTIONAL Locale for output formatting * @return string */ public function toCurrency($value, $script = NULL, $locale = NULL) { //validate the passed number if (!isset($value) || !is_numeric($value)) { throw new Zend_Currency_Exception('the first param should be a number'); } //format the number if (!empty($locale)) { $value = Zend_Locale_Format::toNumber($value, null, $locale); } else { $value = Zend_Locale_Format::toNumber($value, null, $this->_formatLocale); } //localize the number digits if (!empty($script)) { $value = Zend_Locale_Format::convertNumerals($value, 'Default', $script); } else { if (!empty($this->_numberScript)) { $value = Zend_Locale_Format::convertNumerals($value, 'Default', $this->_numberScript); } } //get the sign to be placed next to the number $sign = ''; if ($this->_useSymbol && !empty($this->_symbol)) { $sign = $this->_symbol; } else { if ($this->_useName) { $sign = $this->_fullName; } else { $sign = $this->_shortName; } } //place the sign next to the number if ($this->_signPosition == self::RIGHT) { $value = $value . ' ' . $sign; } else { if ($this->_signPosition == self::LEFT) { $value = $sign . ' ' . $value; } } return $value; }
/** * Returns the internal value * * @param integer $round (Optional) Rounds the value to an given precision, * Default is -1 which returns without rounding * @param string|Zend_Locale $locale (Optional) Locale for number representation */ public function getValue($round = -1, $locale = null) { if ($round < 0) { $return = $this->_value; } else { $return = Zend_Locale_Math::round($this->_value, $round); } if ($locale !== null) { $this->setLocale($locale, true); return Zend_Locale_Format::toNumber($return, array('locale' => $locale)); } return $return; }
/** * test toNumberFormat2 * expected string */ public function testToNumberFormat2() { $this->assertEquals((double) 1.7, (double) Zend_Locale_Format::toNumber(1.7, array('locale' => 'en'))); $this->assertEquals((double) 2.3, (double) Zend_Locale_Format::toNumber(2.3, array('locale' => 'en'))); }
public function formatNumber($value, $precision = 2) { if (null !== $value) { return \Zend_Locale_Format::toNumber($value, array('precision' => $precision, 'locale' => $this->locale)); } }
/** * Fix the percentage for taxes which come with four decimal places * from magento core. * * @param string $label tax label which contains the badly formatted tax percentage * * @return string */ private function fixNumberFormat($label) { $pattern = "/(.*)\\((\\d{1,2}\\.\\d{4}%)\\)/"; if (preg_match($pattern, $label, $matches)) { $percentage = Zend_Locale_Format::toNumber($matches[2], array('locale' => Mage::app()->getLocale()->getLocale(), 'precision' => 2)); return $matches[1] . '(' . $percentage . '%)'; } return $label; }
/** * Returns a localized currency string * * @param integer|float $value Currency value * @param array $options OPTIONAL options to set temporary * @throws Zend_Currency_Exception When the value is not a number * @return string */ public function toCurrency($value, array $options = array()) { // Validate the passed number if (isset($value) === false or is_numeric($value) === false) { require_once 'Zend/Currency/Exception.php'; throw new Zend_Currency_Exception("Value '{$value}' has to be numeric"); } $options = $this->_checkOptions($options) + $this->_options; // Format the number if (empty($options['format']) === true) { $options['format'] = $this->_locale; } $value = Zend_Locale_Format::toNumber($value, array('locale' => $options['format'], 'precision' => $options['precision'])); // Localize the number digits if (empty($options['script']) === false) { $value = Zend_Locale_Format::convertNumerals($value, 'Latn', $options['script']); } // Get the sign to be placed next to the number if (is_numeric($options['display']) === false) { $sign = ' ' . $options['display'] . ' '; } else { switch ($options['display']) { case self::USE_SYMBOL: $sign = ' ' . $options['symbol'] . ' '; break; case self::USE_SHORTNAME: $sign = ' ' . $options['currency'] . ' '; break; case self::USE_NAME: $sign = ' ' . $options['name'] . ' '; break; default: $sign = ''; break; } } // Place the sign next to the number if ($options['position'] === self::RIGHT) { $value = $value . $sign; } else { if ($options['position'] === self::LEFT) { $value = $sign . $value; } } return trim($value); }
/** * Defined by Zend_Filter_Interface * * Normalizes the given input * * @param string $value Value to normalized * @return string|array The normalized value */ public function filter($value) { if (is_array($value)) { require_once 'Zend/Date.php'; $date = new Zend_Date($value, $this->_options['locale']); return $date->toString($this->_options['date_format']); } else { if ($this->_options['precision'] === 0) { return Zend_Locale_Format::toInteger($value, $this->_options); } else { if ($this->_options['precision'] === null) { return Zend_Locale_Format::toFloat($value, $this->_options); } } } return Zend_Locale_Format::toNumber($value, $this->_options); }
/** * @group ZF-9319 */ public function testToNumberWithoutFormatWithPrecision() { $options = array('locale' => 'de_AT', 'precision' => 2); $this->assertEquals('3,99', Zend_Locale_Format::toNumber(3.99, $options)); $this->assertEquals('3,99', Zend_Locale_Format::toNumber(3.994, $options)); $this->assertEquals('4,00', Zend_Locale_Format::toNumber(3.995, $options)); $this->assertEquals('4,00', Zend_Locale_Format::toNumber(3.999, $options)); $this->assertEquals('4,00', Zend_Locale_Format::toNumber(4, $options)); }
/** * Returns a localized currency string * * @param integer|float $value OPTIONAL Currency value * @param array $options OPTIONAL options to set temporary * @throws Zend_Currency_Exception When the value is not a number * @return string */ public function toCurrency($value = null, array $options = array()) { if ($value === null) { if (is_array($options) && isset($options['value'])) { $value = $options['value']; } else { $value = $this->_options['value']; } } if (is_array($value)) { $options += $value; if (isset($options['value'])) { $value = $options['value']; } } // Validate the passed number if (!isset($value) or is_numeric($value) === false) { require_once 'Zend/Currency/Exception.php'; throw new Zend_Currency_Exception("Value '{$value}' has to be numeric"); } if (isset($options['currency'])) { if (!isset($options['locale'])) { $options['locale'] = $this->_options['locale']; } $options['currency'] = self::getShortName($options['currency'], $options['locale']); $options['name'] = self::getName($options['currency'], $options['locale']); $options['symbol'] = self::getSymbol($options['currency'], $options['locale']); } $options = $this->_checkOptions($options) + $this->_options; // Format the number $format = $options['format']; $locale = $options['locale']; if (empty($format)) { $format = Zend_Locale_Data::getContent($locale, 'currencynumber'); } else { if (Zend_Locale::isLocale($format, true, false)) { $locale = $format; $format = Zend_Locale_Data::getContent($format, 'currencynumber'); } } $original = $value; $value = Zend_Locale_Format::toNumber($value, array('locale' => $locale, 'number_format' => $format, 'precision' => $options['precision'])); if ($options['position'] !== self::STANDARD) { $value = str_replace('¤', '', $value); $space = ''; if (iconv_strpos($value, ' ') !== false) { $value = str_replace(' ', '', $value); $space = ' '; } if ($options['position'] == self::LEFT) { $value = '¤' . $space . $value; } else { $value = $value . $space . '¤'; } } // Localize the number digits if (empty($options['script']) === false) { $value = Zend_Locale_Format::convertNumerals($value, 'Latn', $options['script']); } // Get the sign to be placed next to the number if (is_numeric($options['display']) === false) { $sign = $options['display']; } else { switch ($options['display']) { case self::USE_SYMBOL: $sign = $this->_extractPattern($options['symbol'], $original); break; case self::USE_SHORTNAME: $sign = $options['currency']; break; case self::USE_NAME: $sign = $options['name']; break; default: $sign = ''; $value = str_replace(' ', '', $value); break; } } $value = str_replace('¤', $sign, $value); return $value; }
/** * Takes a standard formatted float (eg. 54.33) and converts it to the locale * format needed for display (eg 54,33) * * @param string $pn_value The value to convert * @param string $locale Which locale is to be used to return the value * @return float The converted value */ function caConvertFloatToLocale($pn_value, $locale = "en_US") { try { return Zend_Locale_Format::toNumber($pn_value, array('locale' => $locale)); } catch (Zend_Locale_Exception $e) { return $pn_value; } }