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


PHP Number类代码示例

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


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

示例1: isEquals

 public function isEquals(Number $n)
 {
     if ($this->getValue() == $n->getValue() && $this->isExtra() == $n->isExtra()) {
         return true;
     }
     return false;
 }
开发者ID:zaccydev,项目名称:schemeTest,代码行数:7,代码来源:Number.php

示例2: multiply

 public function multiply(Number $precision, $scale = null)
 {
     $scale = $this->scale($scale);
     $result = bcmul($this->value, $precision->getValue(), self::MAX_PRECISION);
     $diff = $this->round($result, $scale);
     return new self($diff, $scale);
 }
开发者ID:shrikeh,项目名称:precision,代码行数:7,代码来源:Number.php

示例3: echo_test

 public static function echo_test()
 {
     $featureCode = new FeatureCode();
     $featureCode['name'] = 'Echo Test';
     $featureCode['registry'] = array('feature' => 'echo');
     $featureCode->save();
     try {
         $location = Doctrine::getTable('Location')->findAll();
         if (!$location->count()) {
             throw Exception('Could not find location id');
         }
         $location_id = arr::get($location, 0, 'location_id');
         $number = new Number();
         $number['user_id'] = users::getAttr('user_id');
         $number['number'] = '9999';
         $number['location_id'] = $location_id;
         $number['registry'] = array('ignoreFWD' => '0', 'ringtype' => 'ringing', 'timeout' => 20);
         $dialplan = array('terminate' => array('transfer' => 0, 'voicemail' => 0, 'action' => 'hangup'));
         $number['dialplan'] = $dialplan;
         $number['class_type'] = 'FeatureCodeNumber';
         $number['foreign_id'] = $featureCode['feature_code_id'];
         $context = Doctrine::getTable('Context')->findOneByName('Outbound Routes');
         $number['NumberContext']->fromArray(array(0 => array('context_id' => $context['context_id'])));
         $numberType = Doctrine::getTable('NumberType')->findOneByClass('FeatureCodeNumber');
         if (empty($numberType['number_type_id'])) {
             return FALSE;
         }
         $number['NumberPool']->fromArray(array(0 => array('number_type_id' => $numberType['number_type_id'])));
         $number->save();
         return $number['number_id'];
     } catch (Exception $e) {
         kohana::log('error', 'Unable to initialize device number: ' . $e->getMessage());
         throw $e;
     }
 }
开发者ID:swk,项目名称:bluebox,代码行数:35,代码来源:FeatureCodeManager.php

示例4: op_times

 /**
  * String multiplication.
  * this is repeated other times
  *
  * @param Number $other the number of times to repeat this
  * @return SassString the string result
  * @throws StringException
  */
 public function op_times($other)
 {
     if (!$other instanceof Number || !$other->isUnitless()) {
         throw new StringException('Value must be a unitless number', \PHPSass\Script\Parser::$context->node);
     }
     $this->value = str_repeat($this->value, $other->value);
     return $this;
 }
开发者ID:lopo,项目名称:phpsass,代码行数:16,代码来源:SassString.php

示例5: checksum

 /**
  * @param \KataBank\Number $number
  * @return int
  */
 private function checksum(Number $number)
 {
     $checksum = 0;
     $numberOfDigit = count($number->digits());
     foreach ($number->digits() as $digit) {
         $checksum += $numberOfDigit * $digit->value();
         $numberOfDigit--;
     }
     return $checksum;
 }
开发者ID:jdvr,项目名称:KataBankOCR-ObjectCalisthenics,代码行数:14,代码来源:NumberValidator.php

示例6: format

 /**
  * Returns the simplified standard notation format for the given float, decimal number.
  *
  * @param Number $number
  * @return string
  */
 public function format(Number $number)
 {
     /**
      * Move the decimal point to the right for positive exponents of 10.
      * Move the decimal point to the left for negative exponents of 10.
      */
     $coefficient = (string) $number->getCoefficient();
     $decimalPointPosition = strpos($coefficient, ".");
     if ($decimalPointPosition === false) {
         $decimalPointPosition = 1;
     }
     $coefficientWithoutDecimal = str_replace(".", "", $coefficient);
     $newDecimalPointPosition = $decimalPointPosition + $number->getExponent();
     if ($number->getExponent() == 0) {
         // no change to be made from coefficient
         return (string) $number->getCoefficient();
     } else {
         if ($number->getExponent() >= 0 && $newDecimalPointPosition - $decimalPointPosition < $number->getSignificantDigits()) {
             // move decimal point for number > 1
             return substr($coefficientWithoutDecimal, 0, $newDecimalPointPosition) . '.' . substr($coefficientWithoutDecimal, $newDecimalPointPosition);
         } else {
             if ($newDecimalPointPosition > 0) {
                 // pad number > 1 with zeros on the right
                 return str_pad($coefficientWithoutDecimal, $newDecimalPointPosition - $number->getSignificantDigits() + 1, "0", STR_PAD_RIGHT);
             } else {
                 // new decimal point position is less than or equal to zero
                 // pad number < 1 with zeros on the left
                 return "0." . str_pad($coefficientWithoutDecimal, abs($newDecimalPointPosition - $number->getSignificantDigits()), "0", STR_PAD_LEFT);
             }
         }
     }
 }
开发者ID:konrness,项目名称:scientific-notation,代码行数:38,代码来源:StandardNotationFormatter.php

示例7: getPrimeFactors

 public function getPrimeFactors()
 {
     $value = $this->getValue();
     for ($i = 2; $i <= floor(sqrt($value)); $i++) {
         if ($value % $i == 0) {
             $newNumber = new Number($value / $i);
             return array_merge(array($i), $newNumber->getPrimeFactors());
         }
     }
     return array($value);
 }
开发者ID:szabokarlo,项目名称:PrimeFactory,代码行数:11,代码来源:Number.php

示例8: testValidateType

 public function testValidateType()
 {
     $field = new Number("test", "Test");
     $result = $field->validateType("a string");
     $this->assertFalse($result);
     $result = $field->validateType("11");
     $this->assertTrue($result);
     $result = $field->validateType(20);
     $this->assertTrue($result);
     $result = $field->validateType(20.5);
     $this->assertTrue($result);
 }
开发者ID:jenwachter,项目名称:html-form,代码行数:12,代码来源:NumberTest.php

示例9: translate

 /**
  * @param $expression
  * @return bool
  */
 public static function translate($expression)
 {
     if ((String::isValid($expression) || Number::isValid($expression)) && Collection::existsKey(self::$translationMapping, $expression)) {
         $expression = self::$translationMapping[$expression];
     }
     return $expression;
 }
开发者ID:OliverMonneke,项目名称:pennePHP,代码行数:11,代码来源:Boolean.php

示例10: formatValue

 /**
  * Formata o valor
  * @param mixed $value
  * @param string $type
  * @param boolean $formatar
  * @return mixed
  */
 function formatValue($value, $type, $formatar)
 {
     switch (strtolower($type)) {
         case 'data':
         case 'dt':
         case 'date':
             $value = Date::data((string) $value);
             return $formatar ? Date::formatData($value) : $value;
             break;
         case 'timestamp':
         case 'datatime':
             $value = Date::timestamp((string) $value);
             return $formatar ? Date::formatDataTime($value) : $value;
             break;
         case 'real':
             return $formatar ? Number::real($value) : Number::float($value, 2);
         case 'hide':
             return $formatar ? null : $value;
             break;
         case 'array':
             return $formatar ? stringToArray($value) : arrayToString($value);
             break;
         default:
             return $value;
     }
 }
开发者ID:jhonlennon,项目名称:estrutura-mvc,代码行数:33,代码来源:ValueObject.class.php

示例11: breakUp

 public static function breakUp($expressie)
 {
     $parts = array_reverse(str_split($expressie));
     $expressions = [];
     $number = false;
     while (!empty($parts)) {
         $part = array_pop($parts);
         switch ($part) {
             case preg_match('/[0-9.]/', $part) ? true : false:
                 if (!$number) {
                     $expressions[] = $number = new Number();
                 }
                 $number->add($part);
                 break;
             case preg_match('/[+-\\/*]/', $part) ? true : false:
                 $expressions[] = SolverFactory::buildSolver($part);
                 break;
             case preg_match('/[\\[\\]]/', $part) ? true : false:
                 $expressions[] = new Bracket();
                 break;
             default:
                 $number = false;
         }
     }
     return $expressions;
 }
开发者ID:jochenJa,项目名称:simpleCaculator,代码行数:26,代码来源:CalculatorTest.php

示例12: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $number = Number::where('number', $id)->first();
     if ($number->delete()) {
         return array();
     }
     return $this->response->errorInternal();
 }
开发者ID:aa6my,项目名称:nexmo-dashboard,代码行数:14,代码来源:NumberController.php

示例13: postSetupNexmo

 public function postSetupNexmo()
 {
     $nexmo_key = Input::get('nexmo_key');
     $nexmo_secret = Input::get('nexmo_secret');
     $nexmo = new NexmoAccount($nexmo_key, $nexmo_secret);
     try {
         // check nexmo credentials
         $credit_balance = $nexmo->getBalance();
         // check db connection
         DB::connection()->getDatabaseName();
         // migrate db
         Artisan::call('migrate');
         // truncate number table
         DB::table('number')->truncate();
         // set nexmo credentials to env
         Cache::forever('NEXMO_KEY', $nexmo_key);
         Cache::forever('NEXMO_SECRET', $nexmo_secret);
         // add numbers to db
         $numbers = $nexmo->getInboundNumbers();
         if ($numbers['count'] > 0) {
             foreach ($numbers['numbers'] as $num) {
                 $number = new Number();
                 $number->number = $num['msisdn'];
                 $number->country_code = $num['country'];
                 $number->type = $num['type'];
                 $number->features = $num['features'];
                 $number->voice_callback_type = $num['voiceCallbackType'];
                 $number->voice_callback_value = $num['voiceCallbackValue'];
                 $number->save();
             }
         }
         // set dn callback url
         // $nexmo->updateAccountSettings(array('drCallBackUrl' => url('callback/dn')));
         Queue::getIron()->addSubscriber('setupDnCallbackUrl', array('url' => url('queue/receive')));
         Queue::push('HomeController@setupDnCallbackUrl', array('nexmo_key' => $nexmo_key, 'nexmo_secret' => $nexmo_secret), 'setupDnCallbackUrl');
         // set balance to cache
         Cache::put('nexmo', $credit_balance, 10);
         if (Auth::check()) {
             return Redirect::to('/');
         }
         return Redirect::to('/register');
     } catch (Exception $e) {
         return Redirect::to('start')->with('message', $e->__toString());
     }
 }
开发者ID:aa6my,项目名称:nexmo-dashboard,代码行数:45,代码来源:HomeController.php

示例14: validator

 /**
  * Validate input and set value
  * @param mixed
  * @return mixed
  */
 public function validator($varInput)
 {
     try {
         $varInput = Number::create($varInput)->getAmount();
     } catch (\InvalidArgumentException $e) {
         $this->addError($GLOBALS['TL_LANG']['ERR']['numberInputNotAllowed']);
     }
     return parent::validator($varInput);
 }
开发者ID:codefog,项目名称:contao-haste,代码行数:14,代码来源:BackendWidget.php

示例15: __construct

 public function __construct($value)
 {
     parent::__construct($value, 9);
     if (!preg_match('/^[0-9]{9}$/', (string) $value)) {
         throw new InvalidFieldException('Routing "' . $value . '" must be a 9 digit number.');
     }
 }
开发者ID:kulparoman,项目名称:nacha-generator,代码行数:7,代码来源:RoutingNumber.php


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