/** * Filter value * * @param double $value * @return string */ public function filter($value) { $value = floatval($value); $value = Mage::app()->getStore()->roundPrice($this->_rate * $value); //$value = round($value, 2); return $this->_currency->toCurrency($value); }
/** * Filter value * * @param double $value * @return string */ public function filter($value) { $value = Mage::app()->getLocale()->getNumber($value); $value = Mage::app()->getStore()->roundPrice($this->_rate * $value); //$value = round($value, 2); $value = sprintf("%f", $value); return $this->_currency->toCurrency($value); }
/** * @return string */ public function Nice($options = array()) { $amount = $this->getAmount(); if (!isset($options['display'])) { $options['display'] = Zend_Currency::USE_SYMBOL; } if (!isset($options['currency'])) { $options['currency'] = $this->getCurrency(); } if (!isset($options['symbol'])) { $options['symbol'] = $this->currencyLib->getSymbol($this->getCurrency(), $this->getLocale()); } return is_numeric($amount) ? $this->currencyLib->toCurrency($amount, $options) : ''; }
/** * Formats a given value * @see library/Bvb/Grid/Formatter/Bvb_Grid_Formatter_FormatterInterface::format() */ public function format($value) { if ($this->_locale === null || !is_numeric($value)) { return $value; } $currency = new Zend_Currency($this->_locale); return $currency->toCurrency($value); }
/** * Retrives pattern with local date format * @return string */ public function getFormat() { $currency = new Zend_Currency(Mage::app()->getStore()->getBaseCurrency()->getCode(), Mage::app()->getLocale()->getLocaleCode()); $format = $currency->toCurrency('0'); $format = preg_replace('/\\d+.\\d+/', '%f', $format); $format = str_replace(' ', '', $format); return $format; }
/** * Output a formatted currency * * @param integer|float $value Currency value to output * @param string|Zend_Locale|Zend_Currency $currency OPTIONAL Currency to use for this call * @return string Formatted currency */ public function currency($value = null, $currency = null) { if ($value === null) { return $this; } if (is_string($currency) || $currency instanceof Zend_Locale) { if (Zend_Locale::isLocale($currency)) { $currency = array('locale' => $currency); } } if (is_string($currency)) { $currency = array('currency' => $currency); } if (is_array($currency)) { return $this->_currency->toCurrency($value, $currency); } return $this->_currency->toCurrency($value); }
private function _getShippingMultiOptions() { $currency = new Zend_Currency(); $shipping = new Storefront_Model_Shipping(); $options = array(0 => 'Please Select'); foreach ($shipping->getShippingOptions() as $key => $value) { $options["{$value}"] = $key . ' - ' . $currency->toCurrency($value); } return $options; }
/** * Format Price to locale * * @param $price * @return string */ public static function formatPrice($price) { try { $zCurrency = new \Zend_Currency("de_DE"); //TODO: fix to use Zend_Locale return $zCurrency->toCurrency($price, array('symbol' => Tool::getCurrency()->getSymbol())); } catch (\Exception $ex) { echo $ex; } return $price; }
public function preco($especialidade_id, $simbol = true) { $salao_id = Zend_Auth::getInstance()->getIdentity()->salao_id; $modelEspecialidadePreco = new Model_DbTable_EspecialidadePreco(); $preco = $modelEspecialidadePreco->getPrecoEspecialidadeSalao($especialidade_id, $salao_id); if (!$preco) { return ""; } $zendCurrency = new Zend_Currency(); $options = array(); if (!$simbol) { $options = array('precision' => 2, 'symbol' => ''); } return $zendCurrency->toCurrency($preco->especialidade_preco_preco, $options); }
/** * Muestra el dato de la columna * @param /Model/Entity/xxxx $item * @return array */ protected function _getDataColumn($item) { $this->load->library(array("core/fecha/fecha_conversion")); $salida = array(); foreach ($this->_data['columns'] as $key => $value) { if (count($value) > 0) { if (is_array($value['column_table'])) { $obj = $item; foreach ($value['column_table'] as $i => $metodo) { if ((string) $i == "json") { //fb($value['column_json']); $sha = sha1($obj[$metodo]); if (Zend_Registry::isRegistered($sha)) { $json = Zend_Registry::get($sha); } else { $json = Zend_Json::decode($obj[$metodo]); Zend_Registry::set($sha, $json); } $obj = $json[$value['column_json']]; } else { $obj = $obj[$metodo]; } } $valor = $obj; } else { if (isset($value['column_table']) && isset($item[$value['column_table']])) { $valor = $item[$value['column_table']]; } else { $valor = ""; } } switch ($value['column_type']) { case "date": $fecha = $this->fecha_conversion->fechaToDateTime($valor, $value['column_formato']); if ($fecha instanceof DateTime) { $salida[] = $fecha->format($value['column_formato_salida']); } else { $salida[] = ""; } break; case "html": $salida[] = str_replace("?", $valor, $value["column_html"]); break; case "helper": $this->load->helper($value["column_helper_path"]); $parametros = array(); foreach ($value["column_helper_params"] as $h => $param) { if ((string) $h == "json") { $sha = sha1($valor); if (Zend_Registry::isRegistered($sha)) { $json = Zend_Registry::get($sha); } else { $json = Zend_Json::decode($valor); Zend_Registry::set($sha, $json); } if (isset($json[$param])) { $parametros[] = $json[$param]; } else { $parametros[] = ""; } } else { $parametros[] = $item[$param]; } } $salida[] = call_user_func_array($value["column_helper"], $parametros); break; case "money": if (!is_numeric($valor)) { $valor = 0; } $currency = new Zend_Currency(array('value' => $valor)); $currency->setFormat(array("precision" => 0)); $salida[] = $currency->toCurrency(); break; default: $salida[] = $valor; break; } } } return $salida; }
public static function toCurrency($value) { $zendCurrency = new Zend_Currency(); return $zendCurrency->toCurrency($value); }
/** * @ZF-9941 */ public function testSetValueByOutput() { $currency = new Zend_Currency(array('value' => 1000, 'locale' => 'de_AT')); $this->assertEquals('€ 2.000,00', $currency->toCurrency(null, array('value' => 2000))); }
/** * testing setFormat * */ public function testSetFormat() { $locale = new Zend_Locale('en_US'); $USD = new Zend_Currency('USD','en_US'); $USD->setFormat(array('script' => 'Arab')); $this->assertSame('$ ٥٣,٢٩٢.١٨', $USD->toCurrency(53292.18)); $USD->setFormat(array('script' => 'Arab', 'format' => 'de_AT')); $this->assertSame('$ ٥٣.٢٩٢,١٨', $USD->toCurrency(53292.18)); $USD->setFormat(array('script' => 'Latn', 'format' => 'de_AT')); $this->assertSame('$ 53.292,18', $USD->toCurrency(53292.18)); $USD->setFormat(array('script' => 'Latn', 'format' => $locale)); $this->assertSame('$ 53,292.18', $USD->toCurrency(53292.18)); // allignment of currency signs $USD->setFormat(array('position' => Zend_Currency::RIGHT, 'format' => 'de_AT')); $this->assertSame('53.292,18 $', $USD->toCurrency(53292.18)); $USD->setFormat(array('position' => Zend_Currency::RIGHT, 'format' => $locale)); $this->assertSame('53,292.18 $', $USD->toCurrency(53292.18)); $USD->setFormat(array('position' => Zend_Currency::LEFT, 'format' => 'de_AT')); $this->assertSame('$ 53.292,18', $USD->toCurrency(53292.18)); $USD->setFormat(array('position' => Zend_Currency::LEFT, 'format' => $locale)); $this->assertSame('$ 53,292.18', $USD->toCurrency(53292.18)); $USD->setFormat(array('position' => Zend_Currency::STANDARD, 'format' => 'de_AT')); $this->assertSame('$ 53.292,18', $USD->toCurrency(53292.18)); $USD->setFormat(array('position' => Zend_Currency::STANDARD, 'format' => $locale)); $this->assertSame('$ 53,292.18', $USD->toCurrency(53292.18)); // enable/disable currency symbols & currency names $USD->setFormat(array('display' => Zend_Currency::NO_SYMBOL, 'format' => 'de_AT')); $this->assertSame('53.292,18', $USD->toCurrency(53292.18)); $USD->setFormat(array('display' => Zend_Currency::NO_SYMBOL, 'format' => $locale)); $this->assertSame('53,292.18', $USD->toCurrency(53292.18)); $USD->setFormat(array('display' => Zend_Currency::USE_SHORTNAME, 'format' => 'de_AT')); $this->assertSame('USD 53.292,18', $USD->toCurrency(53292.18)); $USD->setFormat(array('display' => Zend_Currency::USE_SHORTNAME, 'format' => $locale)); $this->assertSame('USD 53,292.18', $USD->toCurrency(53292.18)); $USD->setFormat(array('display' => Zend_Currency::USE_NAME, 'format' => 'de_AT')); $this->assertSame('US Dollar 53.292,18', $USD->toCurrency(53292.18)); $USD->setFormat(array('display' => Zend_Currency::USE_NAME, 'format' => $locale)); $this->assertSame('US Dollar 53,292.18', $USD->toCurrency(53292.18)); $USD->setFormat(array('display' => Zend_Currency::USE_SYMBOL, 'format' => 'de_AT')); $this->assertSame('$ 53.292,18', $USD->toCurrency(53292.18)); $USD->setFormat(array('display' => Zend_Currency::USE_SYMBOL, 'format' => $locale)); $this->assertSame('$ 53,292.18', $USD->toCurrency(53292.18)); }
/** * @group GH-516 */ public function testToCurrencyWithLocaleWhichHasParentLocale() { $currency = new Zend_Currency(null, 'es_AR'); $this->assertEquals('$10,00', $currency->toCurrency(10)); }
public function formatCurrency($amount, $locale = null, $currency = null) { $currency = new Zend_Currency($currency, $locale); return $currency->toCurrency($amount); }
/** * testing setFormat * */ public function testSetFormat() { $USD = new Zend_Currency('USD', 'en_US'); $USD->setFormat(null, 'Arab'); $this->assertSame($USD->toCurrency(253292.1832), '$ ٢٥٣,٢٩٢.١٨٣٢'); $USD->setFormat(null, 'Arab', 'de_AT'); $this->assertSame($USD->toCurrency(253292.1832), '$ ٢٥٣.٢٩٢,١٨٣٢'); $USD->setFormat(null, 'Default', 'de_AT'); $this->assertSame($USD->toCurrency(253292.1832), '$ 253.292,1832'); // allignment of currency signs $USD->setFormat(Zend_Currency::RIGHT, null, 'de_AT'); $this->assertSame($USD->toCurrency(253292.1832), '253.292,1832 $'); $USD->setFormat(Zend_Currency::LEFT, null, 'de_AT'); $this->assertSame($USD->toCurrency(253292.1832), '$ 253.292,1832'); $USD->setFormat(Zend_Currency::STANDARD, null, 'de_AT'); $this->assertSame($USD->toCurrency(253292.1832), '$ 253.292,1832'); // enable/disable currency symbols & currency names $USD->setFormat(Zend_Currency::NO_SYMBOL, null, 'de_AT'); $this->assertSame($USD->toCurrency(253292.1832), 'US Dollar 253.292,1832'); $USD->setFormat(Zend_Currency::USE_SHORTNAME, null, 'de_AT'); $this->assertSame($USD->toCurrency(253292.1832), 'USD 253.292,1832'); $USD->setFormat(Zend_Currency::USE_NAME, null, 'de_AT'); $this->assertSame($USD->toCurrency(253292.1832), 'US Dollar 253.292,1832'); $USD->setFormat(Zend_Currency::USE_SYMBOL, null, 'de_AT'); $this->assertSame($USD->toCurrency(253292.1832), '$ 253.292,1832'); }
/** * testing setFormat * */ public function testSetFormat() { $locale = new Zend_Locale('en_US'); $USD = new Zend_Currency('USD','en_US'); $USD->setFormat(array('script' => 'Arab')); $this->assertSame('$ ٥٣,٢٩٢.١٨', $USD->toCurrency(53292.18)); $USD->setFormat(array('script' => 'Arab', 'format' => 'de_AT')); $this->assertSame('$ ٥٣.٢٩٢,١٨', $USD->toCurrency(53292.18)); $USD->setFormat(array('script' => 'Latn', 'format' => 'de_AT')); $this->assertSame('$ 53.292,18', $USD->toCurrency(53292.18)); $USD->setFormat(array('script' => 'Latn', 'format' => $locale)); $this->assertSame('$ 53,292.18', $USD->toCurrency(53292.18)); // allignment of currency signs $USD->setFormat(array('position' => Zend_Currency::RIGHT, 'format' => 'de_AT')); $this->assertSame('53.292,18 $', $USD->toCurrency(53292.18)); $USD->setFormat(array('position' => Zend_Currency::RIGHT, 'format' => $locale)); $this->assertSame('53,292.18 $', $USD->toCurrency(53292.18)); $USD->setFormat(array('position' => Zend_Currency::LEFT, 'format' => 'de_AT')); $this->assertSame('$ 53.292,18', $USD->toCurrency(53292.18)); $USD->setFormat(array('position' => Zend_Currency::LEFT, 'format' => $locale)); $this->assertSame('$ 53,292.18', $USD->toCurrency(53292.18)); $USD->setFormat(array('position' => Zend_Currency::STANDARD, 'format' => 'de_AT')); $this->assertSame('$ 53.292,18', $USD->toCurrency(53292.18)); $USD->setFormat(array('position' => Zend_Currency::STANDARD, 'format' => $locale)); $this->assertSame('$ 53,292.18', $USD->toCurrency(53292.18)); // enable/disable currency symbols & currency names $USD->setFormat(array('display' => Zend_Currency::NO_SYMBOL, 'format' => 'de_AT')); $this->assertSame('53.292,18', $USD->toCurrency(53292.18)); $USD->setFormat(array('display' => Zend_Currency::NO_SYMBOL, 'format' => $locale)); $this->assertSame('53,292.18', $USD->toCurrency(53292.18)); $USD->setFormat(array('display' => Zend_Currency::USE_SHORTNAME, 'format' => 'de_AT')); $this->assertSame('USD 53.292,18', $USD->toCurrency(53292.18)); $USD->setFormat(array('display' => Zend_Currency::USE_SHORTNAME, 'format' => $locale)); $this->assertSame('USD 53,292.18', $USD->toCurrency(53292.18)); $USD->setFormat(array('display' => Zend_Currency::USE_NAME, 'format' => 'de_AT')); $this->assertSame('US Dollar 53.292,18', $USD->toCurrency(53292.18)); $USD->setFormat(array('display' => Zend_Currency::USE_NAME, 'format' => $locale)); $this->assertSame('US Dollar 53,292.18', $USD->toCurrency(53292.18)); $USD->setFormat(array('display' => Zend_Currency::USE_SYMBOL, 'format' => 'de_AT')); $this->assertSame('$ 53.292,18', $USD->toCurrency(53292.18)); $USD->setFormat(array('display' => Zend_Currency::USE_SYMBOL, 'format' => $locale)); $this->assertSame('$ 53,292.18', $USD->toCurrency(53292.18)); try { $USD->setFormat(array('position' => 'unknown')); $this->fail("Exception expected"); } catch (Zend_Currency_Exception $e) { $this->assertContains("Unknown position", $e->getMessage()); } try { $USD->setFormat(array('format' => 'unknown')); $this->fail("Exception expected"); } catch (Zend_Currency_Exception $e) { $this->assertContains("is not a known locale", $e->getMessage()); } try { $USD->setFormat(array('display' => -14)); $this->fail("Exception expected"); } catch (Zend_Currency_Exception $e) { $this->assertContains("Unknown display", $e->getMessage()); } try { $USD->setFormat(array('script' => 'unknown')); $this->fail("Exception expected"); } catch (Zend_Currency_Exception $e) { $this->assertContains("Unknown script", $e->getMessage()); } try { $USD->setFormat(array('unknown' => 'unknown')); $this->fail("Exception expected"); } catch (Zend_Currency_Exception $e) { $this->assertContains("Unknown option", $e->getMessage()); } $USD->setFormat(array('precision' => null)); try { $USD->setFormat(array('precision' => -14)); $this->fail("Exception expected"); } catch (Zend_Currency_Exception $e) { $this->assertContains("precision has to be between", $e->getMessage()); } }
/** * переводит значение заданного типа в строку * * @param mixed $data значение, которое нужно сконвертировать * @param string $type тип данных ('bool','date') * @param int $precision_default задание точного количества знаков после запятой * @return string полученная строка, представляющая данные */ function type_to_str($data, $type, $precision_default = -1) { switch ($type) { case 'encode': return htmlentities($data, ENT_QUOTES, 'utf-8'); case 'translate': return __($data); case "integer": /** * Локально пустые значения спокойно форматируется зендом в 0, * но на сервере, на orbitscipts.com? после форматирования пустого значение, * оно так и остаётся пустое. Я не знаю почему. */ if (is_null($data) || $data == '') { $data = 0; } $res = Zend_Locale_Format::toInteger($data, array('locale' => get_instance()->locale)); return $res; case "float": $precision = 2; /** * Определние нужной точности для денег */ if ($precision_default < 0) { $vals = explode('.', strval((double) $data)); if (isset($vals[1])) { $len = strlen($vals[1]); if ($len > 3) { $precision = 4; } elseif ($len > 2) { $precision = 3; } } } else { $precision = $precision_default; } return number_format($data, $precision, '.', ''); //return Zend_Locale_Format::toFloat($data, array('locale'=> get_instance()->locale)); //return Zend_Locale_Format::toFloat($data, array('locale'=> get_instance()->locale)); case 'procent': return type_to_str($data, 'float', 2) . ' %'; case "money": //return str_replace('%', type_to_str($data, 'float'), get_format('money')); if (is_null($data)) { $data = 0; } /** * @todo Возможно прийдётся определять тип валюты как-то глобально, * когда понадобится использовать что-нибудь отличное от доллара. */ try { $currency = new Zend_Currency(get_instance()->locale, 'USD'); } catch (Zend_Currency_Exception $e) { $currency = new Zend_Currency(get_instance()->default_locale, 'USD'); } $precision = 2; /** * Определние нужной точности для денег */ $vals = explode('.', strval((double) $data)); if (isset($vals[1])) { $len = strlen($vals[1]); } $currency->setFormat(array('precision' => $precision)); try { $value = trim($currency->toCurrency($data)); /** * проверка preg_matchем нужна потмоу что, например в китайском валюта отображается * как: US$0.00 */ if (get_instance()->locale != 'en_US' && preg_match('|^[0-9,\\.\\$\\s\\xc2\\xa0]+$|', $value, $matches)) { $value = '$' . trim(str_replace('$', '', $value)); } } catch (Exception $e) { $value = '0.00'; } return $value; case "nonzeromoney": if ($data == 0) { return "—"; } return type_to_str($data, "money"); case "mysqldate": $data = mktime(0, 0, 0, substr($data, 5, 2), substr($data, 8, 2), substr($data, 0, 4)); return date(get_date_format(), $data); case "mysqlfloat": //return str_replace(',','.',$data); return number_format($data, 8, '.', ''); case 'databasedate': return date("Y-m-d", $data); case 'databasedatetime': return date("Y-m-d H:i:s", $data); case "date": if ($data == 0 || is_null($data)) { return ''; } return date(get_date_format(), $data); case "datetime": $res = date(get_date_format(), $data) . ' ' . date(get_time_format(), $data); return $res; case "bool": return $data ? "true" : "false"; case 'textcode': $num = (int) ($data ^ 67894523); $text = ''; while ($num) { $text .= chr(ord('a') + $num % 26); $num = (int) ($num / 26); } return $text; case "impressions": if ($data < 1000) { return __('< 1 K'); } if ($data < 5000) { return __('1~5 K'); } if ($data < 10000) { return __('5~10 K'); } if ($data < 50000) { return __('10~50 K'); } if ($data < 100000) { return __('50~100 K'); } else { return __('> 100 K'); } case "clicks": if ($data < 100) { return __('< 100'); } if ($data < 900) { return '~ ' . round($data / 100) * 100; } else { return '~ ' . round($data / 1000) . ' K'; } case "mime": return '=?UTF-8?B?' . base64_encode($data) . '?='; default: return $data; } }
/** * 计算金额 * * @param integer $point * @return integer */ public function money($point) { $currency = new Zend_Currency(); return $currency->toCurrency(round(self::FACTOR * $point, 2)); }
?> </a> </td> <td> <?php echo $item->getOrderDate() instanceof Zend_Date ? $item->getOrderDate() : new Zend_Date($item->getOrderDate()); ?> </td> <td><?php echo $item->getItems(); ?> </td> <td> </td> <td class="text-right"><?php echo $totalSum->toCurrency($item->getTotalPrice()); ?> </td> </tr> <?php } ?> </tbody> <tfoot> <tr> <td colspan="4"></td> <td class="text-right"> <strong><?php echo $totalSum; ?> </strong>
/** * Format a number according to locale and currency * @param integer|float $number * @return string * @see Zend_Currency::toCurrency() */ public function toCurrency($value, $currency, $options = array()) { $options = array_merge(array('locale' => $this->getLocale(), 'display' => 2, 'precision' => 2), $options); // Doesn't like locales w/o regions if (is_object($options['locale'])) { $locale = $options['locale']->__toString(); } else { $locale = (string) $options['locale']; } if (strlen($locale) < 5) { $locale = Zend_Locale::getBrowser(); if (is_array($locale)) { foreach ($locale as $browserLocale => $q) { if (strlen($browserLocale) >= 5) { $locale = $browserLocale; break; } } } if (!$locale || strlen($locale) < 5) { $locale = 'en_US'; } } unset($options['locale']); $currency = new Zend_Currency($currency, $locale); return $currency->toCurrency($value, $options); }
/** * Modulo values */ public function testModValues() { $currency = new Zend_Currency(array('currency' => 'EUR', 'locale' => 'de_AT')); $currency->add(801); $currency->mod(2); $this->assertEquals('€ 1,00', $currency->toCurrency()); }
/** * * @param Zend_Db_Table_Row $opcao * @return float */ protected function renderValorOpcao($opcao) { $currency = new Zend_Currency(); return $currency->toCurrency((double) ($opcao['qtde'] * $opcao['opcao']->valor)); }