当前位置: 首页>>代码示例>>PHP>>正文


PHP NumberFormatter::setSymbol方法代码示例

本文整理汇总了PHP中NumberFormatter::setSymbol方法的典型用法代码示例。如果您正苦于以下问题:PHP NumberFormatter::setSymbol方法的具体用法?PHP NumberFormatter::setSymbol怎么用?PHP NumberFormatter::setSymbol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NumberFormatter的用法示例。


在下文中一共展示了NumberFormatter::setSymbol方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: format

 public function format($amount)
 {
     $realFormat = str_replace("\$", "¤", $this->format);
     $numFormatter = new \NumberFormatter(null, \NumberFormatter::PATTERN_DECIMAL, $realFormat);
     $numFormatter->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $this->symbol);
     $numFormatter->setSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL, $this->decimalSeparator);
     $numFormatter->setSymbol(\NumberFormatter::MONETARY_SEPARATOR_SYMBOL, $this->decimalSeparator);
     $numFormatter->setSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, $this->thousandsSeparator);
     $numFormatter->setSymbol(\NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, $this->thousandsSeparator);
     // PHP fix: number of decimal digits is forced without pattern analysis
     // when in currency mode (with currency symbol in format)
     if (strpos($realFormat, "¤") !== FALSE) {
         // Count number of 0 after decimal separator
         $parts = explode(".", $realFormat);
         $decimals = 0;
         if (count($parts) == 2) {
             $decimalPart = $parts[1];
             $decimals = count(explode("0", $decimalPart)) - 1;
         }
         $numFormatter->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $decimals);
     }
     return $numFormatter->format($amount);
 }
开发者ID:booko,项目名称:pasteque-server,代码行数:23,代码来源:Currency.php

示例2: to_decimals

function to_decimals($number, $decimals, $type = \NumberFormatter::DECIMAL)
{
    // ignore empty strings and return
    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    if (!isset($number)) {
        return $number;
    }
    $config = get_instance()->config;
    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    if (empty($config->item('thousands_separator'))) {
        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    }
    $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol'));
    return $fmt->format($number);
}
开发者ID:mnapier,项目名称:opensourcepos,代码行数:17,代码来源:locale_helper.php

示例3: formatAmount

 /**
  * {@inheritdoc}
  */
 public function formatAmount(CurrencyInterface $currency, $amount, $language_type = LanguageInterface::TYPE_CONTENT)
 {
     $currency_locale = $this->localeDelegator->resolveCurrencyLocale();
     $decimal_position = strpos($amount, '.');
     $number_of_decimals = $decimal_position !== FALSE ? strlen(substr($amount, $decimal_position + 1)) : 0;
     $formatter = new \NumberFormatter($currency_locale->getLocale(), \NumberFormatter::PATTERN_DECIMAL, $currency_locale->getPattern());
     $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $number_of_decimals);
     $formatter->setSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL, $currency_locale->getDecimalSeparator());
     $formatter->setSymbol(\NumberFormatter::MONETARY_SEPARATOR_SYMBOL, $currency_locale->getDecimalSeparator());
     $formatter->setSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, $currency_locale->getGroupingSeparator());
     $formatter->setSymbol(\NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL, $currency_locale->getGroupingSeparator());
     $formatter->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $currency->getSign());
     $formatter->setSymbol(\NumberFormatter::INTL_CURRENCY_SYMBOL, $currency->getCurrencyCode());
     return $formatted = $formatter->format($amount);
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:18,代码来源:Intl.php

示例4: localize

 /**
  * {@inheritdoc}
  */
 public function localize($number, array $options = [])
 {
     if (null === $number || '' === $number) {
         return $number;
     }
     $options = $this->getOptions($options);
     if (isset($options['locale'])) {
         $numberFormatter = new \NumberFormatter($options['locale'], \NumberFormatter::DECIMAL);
         if (isset($options['disable_grouping_separator']) && true === $options['disable_grouping_separator']) {
             $numberFormatter->setSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
         }
         if (floor($number) != $number) {
             $numberFormatter->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 2);
             $numberFormatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 4);
         }
         return $numberFormatter->format($number);
     }
     $matchesNumber = $this->getMatchesNumber($number);
     if (!isset($matchesNumber['decimal'])) {
         return $number;
     }
     return str_replace(static::DEFAULT_DECIMAL_SEPARATOR, $options['decimal_separator'], $number);
 }
开发者ID:alexisfroger,项目名称:pim-community-dev,代码行数:26,代码来源:AbstractNumberLocalizer.php

示例5: getFormatter

 /**
  * Creates instance of NumberFormatter class of intl extension
  *
  * @param string $locale
  * @param int $style
  * @param array $attributes
  * @param array $textAttributes
  * @param array $symbols
  * @throws \InvalidArgumentException
  * @return IntlNumberFormatter
  */
 protected function getFormatter($locale, $style, array $attributes = array(), array $textAttributes = array(), array $symbols = array())
 {
     $formatter = new IntlNumberFormatter($locale ?: $this->localeSettings->getLocale(), $this->parseStyle($style));
     foreach ($this->parseAttributes($attributes) as $attribute => $value) {
         $formatter->setAttribute($attribute, $value);
     }
     foreach ($this->parseAttributes($textAttributes) as $attribute => $value) {
         $formatter->setTextAttribute($attribute, $value);
     }
     foreach ($this->parseAttributes($symbols) as $symbol => $value) {
         $formatter->setSymbol($symbol, $value);
     }
     return $formatter;
 }
开发者ID:noglitchyo,项目名称:pim-community-dev,代码行数:25,代码来源:NumberFormatter.php

示例6: display

 /**
  * Return currency amount formatted for display
  *
  * @return StringType
  */
 public function display()
 {
     $formatter = new \NumberFormatter($this->locale->get(), \NumberFormatter::CURRENCY);
     $formatter->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $this->symbol->get());
     $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->precision->get());
     return new StringType(sprintf($this->displayFormat, $formatter->format($this->getAsFloat())));
 }
开发者ID:chippyash,项目名称:currency,代码行数:12,代码来源:Currency.php

示例7: getIntlFormatterWithCurrencyStyle

 protected function getIntlFormatterWithCurrencyStyle()
 {
     if (!$this->isIntlExtensionLoaded()) {
         return null;
     }
     $formatter = new \NumberFormatter('en', \NumberFormatter::CURRENCY);
     $formatter->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, 'SFD');
     return $formatter;
 }
开发者ID:renegare,项目名称:symfony,代码行数:9,代码来源:StubNumberFormatterTest.php

示例8: testFormatWith

 /**
  * @dataProvider providerFormatWith
  *
  * @param string $money    The string representation of the money to test.
  * @param string $locale   The target locale.
  * @param string $symbol   A decimal symbol to apply to the NumberFormatter.
  * @param string $expected The expected output.
  */
 public function testFormatWith($money, $locale, $symbol, $expected)
 {
     $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
     $formatter->setSymbol(\NumberFormatter::MONETARY_SEPARATOR_SYMBOL, $symbol);
     $this->assertSame($expected, Money::parse($money)->formatWith($formatter));
 }
开发者ID:brick,项目名称:money,代码行数:14,代码来源:MoneyTest.php

示例9: check_number_locale

 public function check_number_locale()
 {
     $number_locale = $this->input->post('number_locale');
     $fmt = new \NumberFormatter($number_locale, \NumberFormatter::CURRENCY);
     $currency_symbol = empty($this->input->post('currency_symbol')) ? $fmt->getSymbol(\NumberFormatter::CURRENCY_SYMBOL) : $this->input->post('currency_symbol');
     if ($this->input->post('thousands_separator') == "false") {
         $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
     }
     $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $currency_symbol);
     $number_local_example = $fmt->format(1234567890.123);
     echo json_encode(array('success' => $number_local_example != FALSE, 'number_locale_example' => $number_local_example, 'currency_symbol' => $currency_symbol, 'thousands_separator' => $fmt->getAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL) != ''));
 }
开发者ID:gerarldlee,项目名称:opensourcepos,代码行数:12,代码来源:Config.php


注:本文中的NumberFormatter::setSymbol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。