本文整理汇总了PHP中Zend_Locale_Format::toNumber方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Locale_Format::toNumber方法的具体用法?PHP Zend_Locale_Format::toNumber怎么用?PHP Zend_Locale_Format::toNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Locale_Format
的用法示例。
在下文中一共展示了Zend_Locale_Format::toNumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getDisplayValue
/**
*
*/
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;
}
示例2: format
/**
* 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);
}
示例3: getDisplayValue
/**
*
*/
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;
}
示例4: smarty_modifier_number
/**
* 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);
}
示例5: _createRowObject
/**
* 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;
}
示例6: getAnualPercentageRate
public function getAnualPercentageRate($format = true)
{
$s = Zend_Locale_Format::toNumber($this->_anualPercentageRate, array('precision' => 2));
if ($format) {
return $s . '%';
} else {
return $s;
}
}
示例7: format
/** 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);
}
示例8: number
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;
}
示例9: setValue
/**
* @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;
}
示例10: __toString
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();
}
示例11: Value
/**
* @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 . '%';
}
示例12: Currency
/**
* 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;
}
}
示例13: setValue
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;
}
示例14: getTaxRateIDs
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;
}
示例15: testToNumber
/**
* 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");
}