本文整理汇总了PHP中Number类的典型用法代码示例。如果您正苦于以下问题:PHP Number类的具体用法?PHP Number怎么用?PHP Number使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Number类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: merge
public static function merge($default_params, $input_params)
{
foreach ($default_params as $key => $value) {
if (empty($input_params[$key])) {
continue;
} else {
$value = $input_params[$key];
}
switch ($key) {
case "min_price":
if (Number::isNatural($value)) {
$default_params[$key] = $value;
}
break;
case "max_price":
if (Number::isNatural($value)) {
$default_params[$key] = $value;
}
break;
case "page":
if (Number::isNatural($value)) {
$default_params[$key] = $value;
}
break;
case "limit":
if (Number::isNatural($value) && $value < MAX_LIMIT) {
$default_params[$key] = $value;
}
break;
case "sort":
if ($value == "+price" || $value == "+id" || $value == "-price" || $value == "-id") {
$default_params[$key] = $value;
}
break;
case "category_id":
if (Number::isNatural($value)) {
$default_params[$key] = $value;
}
break;
case "id":
if (Number::isNatural($value)) {
$default_params[$key] = $value;
}
break;
case "keyword":
$default_params[$key] = $value;
break;
default:
// other params will be dropped..
break;
}
}
return $default_params;
}
开发者ID:vtlabo,项目名称:vtlabo-training-php-api,代码行数:54,代码来源:SearchValidator.php
示例16: realExtenso
public static function realExtenso($valor = 0, $maiusculas = false)
{
$valor = Number::float($valor, 2);
# verifica se tem virgula decimal
if (strpos($valor, ",") > 0) {
# retira o ponto de milhar, se tiver
$valor = str_replace(".", "", $valor);
# troca a virgula decimal por ponto decimal
$valor = str_replace(",", ".", $valor);
}
$singular = array("centavo", "real", "mil", "milhão", "bilhão", "trilhão", "quatrilhão");
$plural = array("centavos", "reais", "mil", "milhões", "bilhões", "trilhões", "quatrilhões");
$c = array("", "cem", "duzentos", "trezentos", "quatrocentos", "quinhentos", "seiscentos", "setecentos", "oitocentos", "novecentos");
$d = array("", "dez", "vinte", "trinta", "quarenta", "cinquenta", "sessenta", "setenta", "oitenta", "noventa");
$d10 = array("dez", "onze", "doze", "treze", "quatorze", "quinze", "dezesseis", "dezesete", "dezoito", "dezenove");
$u = array("", "um", "dois", "três", "quatro", "cinco", "seis", "sete", "oito", "nove");
$z = 0;
$valor = number_format($valor, 2, ".", ".");
$inteiro = explode(".", $valor);
$cont = count($inteiro);
for ($i = 0; $i < $cont; $i++) {
for ($ii = strlen($inteiro[$i]); $ii < 3; $ii++) {
$inteiro[$i] = "0" . $inteiro[$i];
}
}
$fim = $cont - ($inteiro[$cont - 1] > 0 ? 1 : 2);
for ($i = 0; $i < $cont; $i++) {
$valor = $inteiro[$i];
$rc = $valor > 100 && $valor < 200 ? "cento" : $c[$valor[0]];
$rd = $valor[1] < 2 ? "" : $d[$valor[1]];
$ru = $valor > 0 ? $valor[1] == 1 ? $d10[$valor[2]] : $u[$valor[2]] : "";
$r = $rc . ($rc && ($rd || $ru) ? " e " : "") . $rd . ($rd && $ru ? " e " : "") . $ru;
$t = $cont - 1 - $i;
$r .= $r ? " " . ($valor > 1 ? $plural[$t] : $singular[$t]) : "";
if ($valor == "000") {
$z++;
} elseif ($z > 0) {
$z--;
}
if ($t == 1 && $z > 0 && $inteiro[0] > 0) {
$r .= ($z > 1 ? " de " : "") . $plural[$t];
}
if ($r) {
$rt = @$rt . ($i > 0 && $i <= $fim && $inteiro[0] > 0 && $z < 1 ? $i < $fim ? ", " : " e " : " ") . $r;
}
}
if (!$maiusculas) {
return trim($rt ? $rt : "zero");
} elseif ($maiusculas == "2") {
return trim(strtoupper($rt) ? strtoupper($rt) : "Zero");
} else {
return trim(ucwords($rt) ? ucwords($rt) : "Zero");
}
}
开发者ID:jhonlennon,项目名称:estrutura-mvc,代码行数:54,代码来源:Number.class.php
示例17: setUp
public function setUp()
{
parent::setUp();
$this->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL ^ Doctrine::EXPORT_CONSTRAINTS);
/*
* Relationships
*/
// Relate the conference (conference_id) with a generic number identifier (foreign_id) in the Number class.
// Note carefully that this only works because this model is related to Number
// The Number class has some "magic" that auto relates the class
$this->hasOne('System as Destination', array('local' => 'foreign_id', 'foreign' => 'system_id', 'owningSide' => TRUE));
}
开发者ID:swk,项目名称:bluebox,代码行数:12,代码来源:SystemNumber.php
示例18: setUp
public function setUp()
{
parent::setUp();
$this->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL ^ Doctrine::EXPORT_CONSTRAINTS);
$this->hasOne('AutoAttendant as Destination', array('local' => 'foreign_id', 'foreign' => 'auto_attendant_id'));
foreach (get_declared_classes() as $class) {
if (is_subclass_of($class, 'Number') or $class == 'Number') {
$numberTable = Doctrine::getTable($class);
$numberTable->bind(array('AutoAttendant', array('local' => 'foreign_id', 'foreign' => 'auto_attendant_id')), Doctrine_Relation::ONE);
}
}
$this->actAs('TelephonyEnabled');
}
开发者ID:swk,项目名称:bluebox,代码行数:13,代码来源:AutoAttendantNumber.php
示例19: dnCallback
public function dnCallback($job, $outbound_chunk_id)
{
$client = new Client();
$outbound_chunk = OutboundChunk::find($outbound_chunk_id);
$number = Number::where('number', $outbound_chunk->outbound->from)->first();
if (filter_var($number->own_callback_url, FILTER_VALIDATE_URL) !== FALSE) {
try {
$client->post($number->own_callback_url, array('headers' => array('Content-Type' => 'application/x-www-form-urlencoded'), 'body' => array_merge($outbound_chunk->toArray(), $outbound_chunk->outbound->toArray(), array('callback_type' => 'dn'))));
} catch (Exception $e) {
}
}
$job->delete();
}
开发者ID:aa6my,项目名称:nexmo-dashboard,代码行数:13,代码来源:OutboundChunk.php
示例20: setUp
public function setUp()
{
parent::setUp();
$this->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_NONE);
$this->hasOne('FaxProfile as Destination', array('local' => 'foreign_id', 'foreign' => 'fxp_id', 'owningSide' => FALSE));
foreach (get_declared_classes() as $class) {
if (is_subclass_of($class, 'Number') or $class == 'Number') {
$deviceTable = Doctrine::getTable($class);
$deviceTable->bind(array('FaxProfile', array('local' => 'foreign_id', 'foreign' => 'fxp_id')), Doctrine_Relation::ONE);
}
}
$this->actAs('TelephonyEnabled');
}
开发者ID:swk,项目名称:bluebox,代码行数:13,代码来源:FaxProfileNumber.php
注:本文中的Number类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论