本文整理汇总了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;
}
示例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);
}
示例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;
}
}
示例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;
}
示例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;
}
示例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);
}
}
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}
示例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();
}
示例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());
}
}
示例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);
}
示例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.');
}
}