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


PHP Number::format方法代码示例

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


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

示例1: showSqlLogs

    public static function showSqlLogs()
    {
        $total = 0;
        foreach (self::$logs['sql'] as $key => $log) {
            $bindings = array();
            if (is_array($log['bindings'])) {
                foreach ($log['bindings'] as $bind) {
                    $bindings[] = $bind[0] . '=' . $bind[1] . ' ' . $bind[2];
                }
            }
            $errorInfo = '';
            $total += $log['time'];
            $classes = array();
            if ($log['errorInfo'][0] != '00000') {
                $errorInfo = ' | ' . $log['errorInfo'][2];
                $classes[] = 'error';
            }
            $classes[] = $log['time'] > 0.5 ? 'alert' : '';
            ?>
				<p class="<?php 
            echo implode(' ', $classes);
            ?>
"><?php 
            echo '[', $key, '] ', $log['sql'], ' | ', implode(',', $bindings), $errorInfo, ' | rows: ' . $log['rows'] . ' | ', Number::format($log['time'], 5, ','), 's';
            ?>
</p>
			<?php 
        }
        ?>
			<p class="total">Total : <?php 
        echo count(self::$logs['sql']);
        ?>
 requête(s) pour <?php 
        echo Number::format($total, 5, ',');
        ?>
s</p>
	<?php 
    }
开发者ID:ben33,项目名称:framework,代码行数:38,代码来源:Logger.php

示例2: format

 /**
  * Format a unit string.
  *
  * @param int|float|string $number The unit amount
  * @param string $unit The unit identifier (eg 'duration/millisecond' or 'millisecond')
  * @param string $width The format name; it can be 'long' (eg '3 milliseconds'), 'short' (eg '3 ms') or 'narrow' (eg '3ms'). You can also add a precision specifier ('long,2' or just '2')
  * @param string $locale The locale to use. If empty we'll use the default locale set in \Punic\Data
  *
  * @return string
  *
  * @throws Exception\ValueNotInList
  */
 public static function format($number, $unit, $width = 'short', $locale = '')
 {
     $data = Data::get('units', $locale);
     $precision = null;
     if (is_int($width)) {
         $precision = $width;
         $width = 'short';
     } elseif (is_string($width) && preg_match('/^(?:(.*),)?([+\\-]?\\d+)$/', $width, $m)) {
         $precision = intval($m[2]);
         $width = $m[1];
         if (!isset($width[0])) {
             $width = 'short';
         }
     }
     if (strpos($width, '_') === 0 || !isset($data[$width])) {
         $widths = array();
         foreach (array_keys($data) as $w) {
             if (strpos($w, '_') !== 0) {
                 $widths[] = $w;
             }
         }
         throw new Exception\ValueNotInList($width, $widths);
     }
     $data = $data[$width];
     if (strpos($unit, '/') === false) {
         $unitCategory = null;
         $unitID = null;
         foreach (array_keys($data) as $c) {
             if (strpos($c, '_') === false) {
                 if (isset($data[$c][$unit])) {
                     if (is_null($unitCategory)) {
                         $unitCategory = $c;
                         $unitID = $unit;
                     } else {
                         $unitCategory = null;
                         break;
                     }
                 }
             }
         }
     } else {
         list($unitCategory, $unitID) = explode('/', $unit, 2);
     }
     $rules = null;
     if (strpos($unit, '_') === false && !is_null($unitCategory) && !is_null($unitID) && isset($data[$unitCategory]) && array_key_exists($unitID, $data[$unitCategory])) {
         $rules = $data[$unitCategory][$unitID];
     }
     if (is_null($rules)) {
         $units = array();
         foreach ($data as $c => $us) {
             if (strpos($c, '_') === false) {
                 foreach (array_keys($us) as $u) {
                     if (strpos($c, '_') === false) {
                         $units[] = "{$c}/{$u}";
                     }
                 }
             }
         }
         throw new \Punic\Exception\ValueNotInList($unit, $units);
     }
     $pluralRule = Plural::getRule($number, $locale);
     //@codeCoverageIgnoreStart
     // These checks aren't necessary since $pluralRule should always be in $rules, but they don't hurt ;)
     if (!isset($rules[$pluralRule])) {
         if (isset($rules['other'])) {
             $pluralRule = 'other';
         } else {
             $availableRules = array_keys($rules);
             $pluralRule = $availableRules[0];
         }
     }
     //@codeCoverageIgnoreEnd
     return sprintf($rules[$pluralRule], Number::format($number, $precision, $locale));
 }
开发者ID:ngreimel,项目名称:kovent,代码行数:86,代码来源:Unit.php


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