Ejemplo n.º 1
0
 /**
  * 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));
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }
Ejemplo n.º 3
0
 /**
  * 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);
 }
Ejemplo n.º 4
0
 /**
  * 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);
 }
Ejemplo n.º 5
0
 /**
  * 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);
 }
Ejemplo n.º 6
0
 public function convert_price($number)
 {
     return CakeNumber::format($number, array('places' => 0, 'before' => ' ', 'escape' => false, 'decimals' => '.', 'thousands' => ','));
 }
Ejemplo n.º 7
0
 /**
  * @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";
 }