Example #1
0
 public function setUp()
 {
     parent::setUp();
     Configure::write('Localization', array('decimals' => ',', 'thousands' => '.'));
     NumberLib::config();
     $this->Numeric = new NumericHelper(new View(null));
 }
Example #2
0
 /**
  * Transforming int values into ordinal numbers (1st, 3rd, ...).
  * When using HTML, you can use <sup>, as well.
  *
  * @param $num (INT) - the number to be suffixed.
  * @param $sup (BOOL) - whether to wrap the suffix in a superscript (<sup>) tag on output.
  * @return string ordinal
  */
 public static function ordinalNumber($num = 0, $sup = false)
 {
     $ordinal = NumberLib::ordinal($num);
     return $sup ? $num . '<sup>' . $ordinal . '</sup>' : $num . $ordinal;
 }
Example #3
0
 /**
  * NumberLibTest::testCurrencyUnknown()
  *
  * @return void
  */
 public function testCurrencyUnknown()
 {
     $result = NumberLib::currency('4.111', 'XYZ');
     $expected = 'XYZ 4,11';
     $this->assertEquals($expected, $result);
 }
 /**
  */
 public static function validateTransactions(&$prepaidAccount, &$transactions)
 {
     if ($prepaidAccount['amount'] == 0 && empty($transactions)) {
         $prepaidAccount['validates'] = true;
         $prepaidAccount['transaction_amount'] = 0;
         return true;
     }
     $total = 0;
     foreach ($transactions as $transaction) {
         $total += $transaction['Transaction']['amount'];
     }
     App::uses('NumberLib', 'Tools.Utility');
     $validates = NumberLib::isFloatEqual($total, $prepaidAccount['amount']);
     $prepaidAccount['validates'] = $validates;
     $prepaidAccount['transaction_amount'] = $total;
     return $validates;
 }
Example #5
0
 /**
  * parse 2,5 - 2.5 2:30 2:31:58 or even 2011-11-12 10:10:10
  * now supports negative values like -2,5 -2,5 -2:30 -:30 or -4
  * @param string
  * @return int: seconds
  * 2011-03-06 ms
  */
 public static function parseTime($duration, $allowed = array(':', '.', ','))
 {
     if (empty($duration)) {
         return 0;
     }
     $parts = explode(' ', $duration);
     $duration = array_pop($parts);
     if (strpos($duration, '.') !== false && in_array('.', $allowed)) {
         App::uses('NumberLib', 'Tools.Lib');
         //$numberLib = new NumberLib();
         $duration = NumberLib::decimalToStandardTime($duration, 2, ':');
     } elseif (strpos($duration, ',') !== false && in_array(',', $allowed)) {
         App::uses('NumberLib', 'Tools.Lib');
         $duration = str_replace(',', '.', $duration);
         $duration = NumberLib::decimalToStandardTime($duration, 2, ':');
     }
     # now there is only the time schema left...
     $pieces = explode(':', $duration, 3);
     $res = 0;
     $hours = abs((int) $pieces[0]) * HOUR;
     //echo pre($hours);
     $isNegative = strpos((string) $pieces[0], '-') !== false ? true : false;
     if (count($pieces) === 3) {
         $res += $hours + (int) $pieces[1] * MINUTE + (int) $pieces[2] * SECOND;
     } elseif (count($pieces) === 2) {
         $res += $hours + (int) $pieces[1] * MINUTE;
     } else {
         $res += $hours;
     }
     if ($isNegative) {
         return -$res;
     }
     return $res;
 }
Example #6
0
 /**
  *2011-04-15 lb
  */
 public function testGetDecimalPlaces()
 {
     $values = array('100' => -2, '0.0001' => 4, '10' => -1, '0.1' => 1, '1' => 0, '0.001' => 3);
     foreach ($values as $was => $expected) {
         $is = NumberLib::getDecimalPlaces($was, 10);
         $this->assertSame($expected, $is);
         //, null, $was
     }
 }
 /**
  * get the rounded average
  * @param array $values: int or float values
  * @return int $average
  * @static
  * move to lib
  * 2009-09-05 ms
  */
 public static function average($values, $precision = 0)
 {
     trigger_error('deprecated - use Tools.NumberLib instead');
     App::uses('NumberLib', 'Tools.Utility');
     return NumberLib::average($values, $precision);
 }