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


PHP NumberFormatter::setPattern方法代码示例

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


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

示例1: create

 /**
  * Creates a number formatter according to options and with predefined formats.
  *
  * @param array $options
  *
  * @return \NumberFormatter
  */
 public function create(array $options)
 {
     $options = $this->resolve($options);
     $formatter = new \NumberFormatter($options['locale'], $options['type']);
     if (null !== $options['number_format']) {
         $formatter->setPattern($options['number_format']);
     }
     return $formatter;
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:16,代码来源:NumberFactory.php

示例2: convert

 public function convert()
 {
     $formatter = new \NumberFormatter($this->locale, \NumberFormatter::PATTERN_DECIMAL);
     foreach ($this->binaryPrefixes as $size => $unitPattern) {
         if ($size <= $this->number) {
             $value = $this->number >= self::CONVERT_THRESHOLD ? $this->number / (double) $size : $this->number;
             $formatter->setPattern($unitPattern);
             return $formatter->format($value);
         }
     }
     return $formatter->format($this->number);
 }
开发者ID:camigreen,项目名称:php-humanizer,代码行数:12,代码来源:MetricSuffix.php

示例3: moneda

 public static function moneda($entero, $localidad = null, $codigo = null)
 {
     if (empty($entero)) {
         return $entero;
     }
     $localidad = empty($localidad) ? self::LOCALIDAD_RD : $localidad;
     $codigo = empty($codigo) ? self::CODIGO_RD : $codigo;
     $sufijo = $localidad == 'es_DO' ? 'RD' : '';
     $fmt = new NumberFormatter($localidad, NumberFormatter::CURRENCY);
     //$fmt->setTextAttribute(NumberFormatter::CURRENCY_CODE, 'DOP');
     $fmt->setPattern(str_replace('¤#', '¤ #', $fmt->getPattern()));
     return $sufijo . $fmt->formatCurrency($entero, $codigo);
     //setlocale(LC_MONETARY, $localidad);
     //return money_format('%i', $entero) . "\n";
 }
开发者ID:alejandrososa,项目名称:ventasYii,代码行数:15,代码来源:FormatoHelper.php

示例4: formatUang

 public function formatUang($value, $currency)
 {
     /* if($currency == 'Rupee India'){
     			$fmt = new NumberFormatter( 'en_IN', NumberFormatter::CURRENCY );		
     		}else{
     			$fmt = new NumberFormatter( 'en_US', NumberFormatter::CURRENCY );		
     		}
     		
     		if($currency == 'Rupiah Indonesia'){
     			$currency = 'IDR';
     		}elseif($currency == 'Dollar Amerika'){
     			$currency = 'USD';
     		}elseif($currency == 'Dollar Singapura'){
     			$currency = 'SGD';
     		}elseif($currency == 'Baht Thailand'){
     			$currency = 'THB';
     		}elseif($currency == 'Peso Argentina'){
     			$currency = 'ARS';
     		}elseif($currency == 'Ringgit Malaysia'){
     			$currency = 'MYR';
     		}elseif($currency == 'Yen Jepang'){
     			$currency = 'JPY';
     		} */
     if ($currency == 'INR') {
         $fmt = new NumberFormatter('en_IN', NumberFormatter::CURRENCY);
     } else {
         $fmt = new NumberFormatter('IND', NumberFormatter::CURRENCY);
     }
     $sMyPattern = "¤ #,##0.00;-¤ #,##0.00";
     $fmt->setPattern($sMyPattern);
     return $fmt->formatCurrency($value, $currency);
 }
开发者ID:prap44,项目名称:SKT-MIGAS-ESDM,代码行数:32,代码来源:perusahaan.php

示例5: formatNumber

 /**
  * Formato numero conforme locale
  *
  * @param int   $valor    Integer Valor
  * @param float $decimais Float Decimais
  *
  * @return string
  * @example : formatNumber(8712.335) = 8.712,34
  */
 function formatNumber($valor, $decimais = 2)
 {
     $valor = floatval($valor);
     $decimais = intval($decimais);
     $pattern = sprintf('#,##0.%s', str_pad('', $decimais, '0'));
     $fmt = new \NumberFormatter(config('app.locale'), \NumberFormatter::DECIMAL);
     $fmt->setPattern($pattern);
     return $fmt->format($valor);
 }
开发者ID:naturalweb,项目名称:nwlaravel,代码行数:18,代码来源:helpers.php

示例6: prepareDemo11Grid

 protected function prepareDemo11Grid()
 {
     $input = new InputSource($_GET);
     $grid = new Grid($provider = $this->getDataProvider(), [new TableCaption('Demo 11: Customization. Table Caption'), new Column('id'), new Column('name'), new Column('role'), new Column('birthday'), (new Column('age'))->setValueCalculator(function ($row) {
         return DateTime::createFromFormat('Y-m-d', $row->birthday)->diff(new DateTime('now'))->y;
     })->setValueFormatter(function ($val) {
         return "{$val} years";
     }), (new Column('income'))->setValueFormatter(function ($value) {
         if (!class_exists('\\NumberFormatter')) {
             return '$' . $value;
         }
         static $numberFormatter;
         if ($numberFormatter === null) {
             $numberFormatter = new \NumberFormatter('en_US', \NumberFormatter::CURRENCY);
             $numberFormatter->setPattern('<span style="color:green">¤</span>#,##0.00;-<span style="color:red">¤</span>#,##0.00');
         }
         return $numberFormatter->format($value);
     }), new FilterControl('name', FilterOperation::OPERATOR_EQ, $input('name')), (new FilterControl('role', FilterOperation::OPERATOR_EQ, $input('role')))->setView(new TemplateView('select', ['options' => ['' => 'All Roles', 'User' => 'Users', 'Manager' => 'Managers', 'Admin' => 'Admins']])), new PageSizeSelectControl($input('ps', 10), [5, 10, 20, 50, 100]), new CsvExport($input('csv')), new ResetButton(), new PageTotalsRow(['id' => function () {
         return 'Page totals';
     }, 'age' => PageTotalsRow::OPERATION_AVG, 'income' => PageTotalsRow::OPERATION_SUM]), new PaginationControl($input('page', 1), 10, $provider), new ColumnSortingControl('id', new InputOption('sort', $_GET)), new ColumnSortingControl('birthday', new InputOption('sort', $_GET))]);
     $grid->getTileRow()->detach()->attachTo($grid->getTableHeading());
     $grid->attachTo($this->layout());
 }
开发者ID:view-components,项目名称:grids,代码行数:23,代码来源:Controller.php

示例7: nReal

 /**
  * Mostra o Valor no real Formatado
  * @param float $number
  * @param boolean $fixed
  * @param boolean $symbol
  * @param integer $decimals
  * @return string
  */
 public static function nReal($number, $decimals = 2, $symbol = true, $fixed = true)
 {
     if (is_null($number) || empty(self::onlyNumbers($number))) {
         return '';
     }
     $formater = new \NumberFormatter("pt-BR", \NumberFormatter::CURRENCY);
     $formater->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $fixed ? $decimals : 1);
     if ($decimals === false) {
         $decimals = 2;
         preg_match_all('/[0-9][^0-9]([0-9]+)/', $number, $matches);
         if (!empty($matches[1])) {
             $decimals = strlen(rtrim($matches[1][0], 0));
         }
     }
     $formater->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
     if (!$symbol) {
         $pattern = preg_replace("/[¤]/", '', $formater->getPattern());
         $formater->setPattern($pattern);
     } else {
         // ESPAÇO DEPOIS DO SIMBOLO
         $pattern = str_replace("¤", "¤ ", $formater->getPattern());
         $formater->setPattern($pattern);
     }
     return $formater->formatCurrency($number, $formater->getTextAttribute(\NumberFormatter::CURRENCY_CODE));
 }
开发者ID:eduardokum,项目名称:laravel-boleto,代码行数:33,代码来源:Util.php


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