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


PHP CakeNumber::format方法代码示例

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


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

示例1: standardFormat

 /**
  * Transforms $number into a standard format.
  *
  * 	12345.67	=	12,346
  *
  * @param integer $number The number to format.
  * @param string $before The text to put in front of the number Default is ''.
  * @param integer $places The number to decimal places to show. Default is 0.
  * @return string The formated number.
  * @access public
  * @static
  */
 public static function standardFormat($number, $before = '', $places = 0)
 {
     if ($places === 0) {
         $number = round($number);
     }
     return CakeNumber::format($number, array('before' => $before, 'places' => $places));
 }
开发者ID:quentinhill,项目名称:bedrock,代码行数:19,代码来源:BedrockNumber.php

示例2: testMultibyteFormat

 /**
  * testMultibyteFormat
  *
  * @return void
  */
 public function testMultibyteFormat()
 {
     $value = '5199100.0006';
     $result = $this->Number->format($value, array('thousands' => ' ', 'decimals' => '&', 'places' => 3, 'escape' => false, 'before' => ''));
     $expected = '5 199 100&001';
     $this->assertEquals($expected, $result);
     $value = 1000.45;
     $result = $this->Number->format($value, array('thousands' => ',,', 'decimals' => '.a', 'escape' => false));
     $expected = '$1,,000.a45';
     $this->assertEquals($expected, $result);
     $value = 519919827593784.0;
     $this->Number->addFormat('RUR', array('thousands' => 'ø€ƒ‡™', 'decimals' => '(§.§)', 'escape' => false, 'wholeSymbol' => '€', 'wholePosition' => 'after'));
     $result = $this->Number->currency($value, 'RUR');
     $expected = '519ø€ƒ‡™919ø€ƒ‡™827ø€ƒ‡™593ø€ƒ‡™784(§.§)00€';
     $this->assertEquals($expected, $result);
     $value = '13371337.1337';
     $result = CakeNumber::format($value, array('thousands' => '- |-| /-\\ >< () |2 -', 'decimals' => '- £€€† -', 'before' => ''));
     $expected = '13- |-| /-\\ &gt;&lt; () |2 -371- |-| /-\\ &gt;&lt; () |2 -337- £€€† -13';
     $this->assertEquals($expected, $result);
 }
开发者ID:beyondkeysystem,项目名称:testone,代码行数:25,代码来源:CakeNumberTest.php

示例3: format

 /**
  * Format numeric values
  * should not be used for currencies
  * //TODO: automize per localeconv() ?
  *
  * @param float $number
  * @param array $options : currency=true/false, ... (leave empty for no special treatment)
  * @return string
  */
 public static function format($number, $formatOptions = [])
 {
     if (!is_numeric($number)) {
         $default = '---';
         if (!empty($options['default'])) {
             $default = $options['default'];
         }
         return $default;
     }
     if ($formatOptions === false) {
         $formatOptions = [];
     } elseif (!is_array($formatOptions)) {
         $formatOptions = ['places' => $formatOptions];
     }
     $options = ['before' => '', 'after' => '', 'places' => 2, 'thousands' => static::$_thousands, 'decimals' => static::$_decimals, 'escape' => false];
     $options = $formatOptions + $options;
     if (!empty($options['currency'])) {
         if (!empty(static::$_symbolRight)) {
             $options['after'] = ' ' . static::$_symbolRight;
         } elseif (!empty(static::$_symbolLeft)) {
             $options['before'] = static::$_symbolLeft . ' ';
         }
     }
     /*
     		if ($spacer !== false) {
     			$spacer = ($spacer === true) ? ' ' : $spacer;
     			if ((string)$before !== '') {
     				$before .= $spacer;
     			}
     			if ((string)$after !== '') {
     				$after = $spacer . $after;
     			}
     		}
     */
     if ($options['places'] < 0) {
         $number = round($number, $options['places']);
     }
     $sign = '';
     if ($number > 0 && !empty($options['signed'])) {
         $sign = '+';
     }
     if (isset($options['signed'])) {
         unset($options['signed']);
     }
     return $sign . parent::format($number, $options);
 }
开发者ID:ByMyHandsOnly,项目名称:BMHO_Web,代码行数:55,代码来源:NumberLib.php

示例4: format

 /**
  * Formats a number into a currency format.
  *
  * @param float $number A floating point number
  * @param int $options If integer then places, if string then before, if (,.-) then use it
  *   or array with places and before keys
  * @return string formatted number
  * @see CakeNumber::format()
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::format
  */
 public function format($number, $options = false)
 {
     return $this->_engine->format($number, $options);
 }
开发者ID:yuuicchan0912,项目名称:sample2,代码行数:14,代码来源:NumberHelper.php

示例5: format

 /**
  * format numeric values
  * should not be used for currencies
  * 
  * @param float $number
  * @param int $places (0 = int, 1..x places after dec, -1..-x places before dec)
  * @param array $option : currency=true/false, ... (leave empty for no special treatment)
  * //TODO: automize per localeconv() ?
  * 2009-04-03 ms
  */
 public static function format($number, $formatOptions = array())
 {
     if (!is_numeric($number)) {
         $default = '---';
         if (!empty($options['default'])) {
             $default = $options['default'];
         }
         return $default;
     }
     if ($formatOptions === false) {
         $formatOptions = array();
     }
     $options = array('before' => '', 'after' => '', 'places' => 2, 'thousands' => self::$_thousandsPoint, 'decimals' => self::$_decimalPoint, 'escape' => false);
     $options = am($options, $formatOptions);
     //$options = array;
     if (!empty($options['currency'])) {
         if (!empty(self::$_symbolRight)) {
             $options['after'] = ' ' . self::$_symbolRight;
         } elseif (!empty(self::$_symbolLeft)) {
             $options['before'] = self::$_symbolLeft . ' ';
         }
     }
     /*
     else {
     	if (!empty($formatOptions['after'])) {
     		$options['after'] = $formatOptions['after'];
     	}
     	if (!empty($formatOptions['before'])) {
     		$options['before'] = $formatOptions['before'];
     	}
     }
     if (!empty($formatOptions['thousands'])) {
     	$options['thousands'] = $formatOptions['thousands'];
     }
     if (!empty($formatOptions['decimals'])) {
     	$options['decimals'] = $formatOptions['decimals'];
     }
     */
     if ($options['places'] < 0) {
         $number = round($number, $options['places']);
     }
     $sign = '';
     if ($number > 0 && !empty($options['signed'])) {
         $sign = '+';
     }
     return $sign . parent::format($number, $options);
 }
开发者ID:robksawyer,项目名称:grabitdown,代码行数:57,代码来源:NumberLib.php

示例6: convert_price

 public function convert_price($number)
 {
     return CakeNumber::format($number, array('places' => 0, 'before' => ' ', 'escape' => false, 'decimals' => '.', 'thousands' => ','));
 }
开发者ID:hocnguyen,项目名称:mail_template,代码行数:4,代码来源:CommonsHelper.php

示例7: getItemName

 /**
  * @param totalCodes The total number of codes the user is purchasing
  */
 public function getItemName($totalCodes)
 {
     // called as CakeNumber
     App::uses('CakeNumber', 'Utility');
     $itemName = CakeNumber::format($totalCodes, array('places' => 0, 'before' => '', 'escape' => false, 'thousands' => ','));
     return $itemName . " download codes";
 }
开发者ID:robksawyer,项目名称:grabitdown,代码行数:10,代码来源:Code.php


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