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


PHP NumberFormatter::format方法代码示例

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


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

示例1: porExtenso

 /**
  * Retorna número no formato brasileiro (locale: pt_BR, currency: BRL) por extenso
  * 
  * @param number $number 
  * @return string no formato brasileiro (locale: pt_BR, currency: BRL) por extenso
  */
 public function porExtenso($number)
 {
     if (!is_numeric($number)) {
         return false;
     }
     $numero_extenso = '';
     $arr = explode(".", $number);
     $inteiro = $arr[0];
     if (isset($arr[1])) {
         $decimos = strlen($arr[1]) == 1 ? $arr[1] . '0' : $arr[1];
     }
     $fmt = new \NumberFormatter('br', \NumberFormatter::SPELLOUT);
     if (is_array($arr)) {
         $numero_extenso = $fmt->format($inteiro) . ' reais';
         if (isset($decimos) && $decimos > 0) {
             $numero_extenso .= ' e ' . $fmt->format($decimos) . ' centavos';
         }
     }
     return $numero_extenso;
 }
开发者ID:adaoex,项目名称:zf2-base,代码行数:26,代码来源:Moeda.php

示例2: serializeFloatType

 /**
  * @param VisitorInterface $visitor
  * @param FloatType        $data
  * @param array            $type
  * @param Context          $context
  *
  * @return mixed|void
  */
 public function serializeFloatType(VisitorInterface $visitor, FloatType $data, array $type, Context $context)
 {
     $numberFormatter = new \NumberFormatter($this->getLocale($type), $this->getFormat($type));
     if ($visitor instanceof XmlSerializationVisitor && false === $this->xmlCData) {
         return $visitor->visitSimpleString($numberFormatter->format($data->getValue()), $type, $context);
     }
     return $visitor->visitString($numberFormatter->format($data->getValue()), $type, $context);
 }
开发者ID:next-sentence,项目名称:afterbuy-sdk,代码行数:16,代码来源:FloatHandler.php

示例3: 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

示例4: render

 public function render(\Erebot\IntlInterface $translator)
 {
     $locale = $translator->getLocale(\Erebot\IntlInterface::LC_NUMERIC);
     $formatter = new \NumberFormatter($locale, \NumberFormatter::IGNORE);
     $result = (string) $formatter->format($this->value, \NumberFormatter::TYPE_INT32);
     return $result;
 }
开发者ID:erebot,项目名称:styling,代码行数:7,代码来源:IntegerVariable.php

示例5: bytesToHuman

 public function bytesToHuman($bytes, $precision = 2)
 {
     $suffixes = ['bytes', 'kB', 'MB', 'GB', 'TB'];
     $formatter = new \NumberFormatter($this->translator->getLocale(), \NumberFormatter::PATTERN_DECIMAL, 0 === $precision ? '#' : '.' . str_repeat('#', $precision));
     $exp = floor(log($bytes, 1024));
     return $formatter->format($bytes / pow(1024, floor($exp))) . ' ' . $this->translator->trans($suffixes[$exp]);
 }
开发者ID:stof,项目名称:Gitiki,代码行数:7,代码来源:CoreExtension.php

示例6: decimalNumber

 /**
  * Formatação de numero decimal
  * @param float/integer $value
  * @param integer $precision
  * @param string $language
  * @return float
  */
 public static function decimalNumber($value, $precision = 2, $language = 'pt_BR')
 {
     $valDecimal = new \NumberFormatter($language, \NumberFormatter::DECIMAL);
     $valDecimal->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $precision);
     $valDecimal->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $precision);
     return $valDecimal->format((double) $value, \NumberFormatter::TYPE_DOUBLE);
 }
开发者ID:cityware,项目名称:city-format,代码行数:14,代码来源:Number.php

示例7: formatI18nDecimal

 /**
  * localized format for money with the NumberFormatter class in Decimal mode
  * without currency symbol
  * like 1.234,56
  *
  * @param Money $money
  * @param null  $locale
  * @return bool|string
  */
 public function formatI18nDecimal(Money $money, $locale = null)
 {
     if ($locale === null) {
         $locale = $this->locale;
     }
     $formatter = new \NumberFormatter($locale, \NumberFormatter::DECIMAL);
     return $formatter->format($money->getConvertedAmount());
 }
开发者ID:ivoba,项目名称:money-twig-extension,代码行数:17,代码来源:MoneyFormatter.php

示例8: porExtenso

 /**
  * Retorna número por extenso
  * @param int $number 
  * @return string número por extenso
  */
 public function porExtenso($number)
 {
     if (!is_numeric($number)) {
         return false;
     }
     $fmt = new \NumberFormatter('br', \NumberFormatter::SPELLOUT);
     return $fmt->format($number);
 }
开发者ID:adaoex,项目名称:zf2-base,代码行数:13,代码来源:Numero.php

示例9: spell

 /**
  * 数值转为中文拼读
  */
 public static function spell($number, $capital = false)
 {
     $formatter = new \NumberFormatter('zh_CN', \NumberFormatter::SPELLOUT);
     $sentence = $formatter->format($number);
     if ($capital) {
         $sentence = self::mbStrtr($sentence, self::$chars, self::$caps);
     }
     return $sentence;
 }
开发者ID:azhai,项目名称:CuteLib,代码行数:12,代码来源:Word.php

示例10: render

 public function render(\Erebot\IntlInterface $translator)
 {
     $locale = $translator->getLocale(\Erebot\IntlInterface::LC_NUMERIC);
     $formatter = new \NumberFormatter($locale, \NumberFormatter::DECIMAL);
     $formatter->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 0);
     $formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 100);
     $result = (string) $formatter->format($this->value);
     return $result;
 }
开发者ID:erebot,项目名称:styling,代码行数:9,代码来源:FloatVariable.php

示例11: Repeat

 public static function Repeat($times)
 {
     $list = new ArrayList();
     $formatter = new NumberFormatter('en-NZ', NumberFormatter::SPELLOUT);
     for ($i = 1; $i <= $times; $i++) {
         $list->push(array('Num' => $i, 'Word' => ucwords(strtolower($formatter->format($i)))));
     }
     return $list;
 }
开发者ID:helpfulrobot,项目名称:webfox-silverstripe-helpers,代码行数:9,代码来源:HelpersTemplateProvider.php

示例12: format

 /**
  * {@inheritdoc}
  */
 public function format($value)
 {
     $uiLocale = $this->getUiLocale();
     if (null === $uiLocale) {
         return $value;
     }
     $numberFormatter = new \NumberFormatter($uiLocale, \NumberFormatter::DECIMAL);
     $numberFormatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->getDecimalCount($value));
     return $numberFormatter->format($value);
 }
开发者ID:paulclarkin,项目名称:pim-community-dev,代码行数:13,代码来源:NumberFormatter.php

示例13: smarty_function_numberDecimal

function smarty_function_numberDecimal(array $params, Smarty_Internal_Template $template)
{
    $value = $params['value'];
    if (!is_numeric($value)) {
        throw new CM_Exception_Invalid('Invalid non-numeric value');
    }
    /** @var CM_Frontend_Render $render */
    $render = $template->getTemplateVars('render');
    $formatter = new NumberFormatter($render->getLocale(), NumberFormatter::DECIMAL);
    return $formatter->format($value);
}
开发者ID:cargomedia,项目名称:cm,代码行数:11,代码来源:function.numberDecimal.php

示例14: format

 /**
  * Format the specified number to a string with the specified number of
  * fractional digits.
  *
  * @param
  *        	double d
  *        	The number to format.
  * @param
  *        	int digits
  *        	The number of fractional digits.
  * @return string The number formatted as a string.
  */
 public function format($d, $digits)
 {
     $this->synchronized(function ($thread) {
         if (is_infinite($d) || is_nan($d)) {
             return "0";
         }
         $this->numberFormatter->setAttribute(\NumberFormatter::GROUPING_USED, false);
         $this->numberFormatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $digits);
         return $this->numberFormatter->format($d);
     });
 }
开发者ID:katrinaniolet,项目名称:encog-php-core,代码行数:23,代码来源:CSVFormat.php

示例15: entityToHtml

 private function entityToHtml($ent = null, $html = '')
 {
     //debug($ent);
     //die();
     $spellf = new \NumberFormatter("es", \NumberFormatter::SPELLOUT);
     $totalImporte = array_sum(array_column($ent->cuotas_polizas, 'pagado'));
     $html = str_replace("[NroRecibo]", $ent->id + $this->primerRecibo, $html);
     $html = str_replace("[Fecha]", $ent->created, $html);
     $html = str_replace("[Cliente]", $ent->client->razonSocial, $html);
     $html = str_replace("[TotalPalabras]", $spellf->format($ent->cuotas_polizas[0]['pagado']), $html);
     return $html;
 }
开发者ID:ElWray,项目名称:JCMv2,代码行数:12,代码来源:RecibosController.php


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