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


PHP float类代码示例

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


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

示例1: convertNumberToRational

 /**
  * Convert if possible a supplied argument to a rational
  *
  * @param int|float|string|NumericTypeInterface $value
  *
  * @return \Chippyash\Math\Matrix\RationalNumber
  *
  * @throws \Chippyash\Matrix\Exceptions\MatrixException
  * @throws \Exception
  */
 protected function convertNumberToRational($value)
 {
     if ($value instanceof NumericTypeInterface) {
         return $value->asRational();
     }
     switch (gettype($value)) {
         case 'integer':
             return RationalTypeFactory::create($value, 1);
         case 'double':
             return RationalTypeFactory::fromFloat($value);
         case 'string':
             try {
                 return RationalTypeFactory::fromString($value);
             } catch (\Exception $e) {
                 try {
                     return ComplexTypeFactory::fromString($value)->asRational();
                 } catch (\Exception $ex) {
                     throw new MatrixException('The string representation of the number is invalid for a rational');
                 }
             }
         case 'NULL':
             return RationalTypeFactory::create(0, 1);
         case 'boolean':
             return RationalTypeFactory::create($value ? 1 : 0, 1);
         default:
             throw new MatrixException('Rational expects int, float, string, Rational or NumericTypeInterface ');
     }
 }
开发者ID:chippyash,项目名称:math-matrix,代码行数:38,代码来源:ConvertNumberToRational.php

示例2: __construct

 /**
  * @param \DateTime|string|float $input    The date or a string the DateTime c'tor can understand or a timestamp
  * @param \DateTimeZone|string   $timezone The timezone or a string the DateTimeZone c'tor can understand
  */
 public function __construct($input, $timezone)
 {
     if (!$timezone instanceof \DateTimeZone) {
         $timezone = new \DateTimeZone((string) $timezone);
     }
     /////
     // We have to trick PHP a bit here, but why?
     //
     // Apparently things behave different, when setting a timezone like
     // a) 'Europe/Berlin'
     // b) '+02:00'
     //
     // When the date already has a timezone set then
     // a) will only set the timezone
     // b) will set the timezone and will also change the timestamp by 2 hours
     //
     // Therefore we create a fresh date, that does not have a timezone yet, set the timestamp, and then apply the
     // timezone
     //
     // See the unit tests for more as well
     ////
     if ($input instanceof \DateTime) {
         $date = (new \DateTime())->setTimestamp($input->getTimestamp())->setTimezone($timezone);
     } elseif (is_numeric($input)) {
         $date = (new \DateTime())->setTimestamp($input)->setTimezone($timezone);
     } else {
         // when we have string input, we immediately use the timezone
         $tmp = new \DateTime($input, $timezone);
         // we reconstruct the date time again in order to set the timezone on the inner one
         $date = (new \DateTime())->setTimestamp($tmp->getTimestamp())->setTimezone($timezone);
     }
     $this->date = $date;
     $this->timezone = $timezone;
 }
开发者ID:peekandpoke,项目名称:psi,代码行数:38,代码来源:LocalDate.php

示例3: getPrice

 /**
  * @return float
  */
 public function getPrice($object = false)
 {
     if (true === $object) {
         return $this->money;
     }
     return $this->money->getAmount();
 }
开发者ID:poulikov,项目名称:mongodb-odm,代码行数:10,代码来源:Option.php

示例4: divide

 /**
  * Divides $this by $divisor and returns a new value object.
  * Uses the default rounding method (ROUND_HALF_EVEN) which is preferred for financial calculations.
  * @param Money|int|float|string $divisor
  * @return Money|string
  */
 public function divide($divisor)
 {
     if ($divisor instanceof Money) {
         return $this->mathProvider->divide($this->getValue(), $divisor->getValue(), MathProvider::ROUND_MODE_NONE);
     } else {
         return new static($this->mathProvider->divide($this->getValue(), (string) $divisor), $this->mathProvider);
     }
 }
开发者ID:lusitanian,项目名称:phpmoney,代码行数:14,代码来源:Money.php

示例5: elseif

 /**
  * @param string|int|float|\Enimiste\Math\VO\IntegerNumber $value
  *
  * @return \Enimiste\Math\VO\FloatNumber
  */
 function as_integer_number($value)
 {
     if ($value instanceof \Enimiste\Math\VO\IntegerNumber) {
         return $value;
     } elseif ($value instanceof \Enimiste\Math\VO\FloatNumber) {
         return new \Enimiste\Math\VO\IntegerNumber($value->__toString());
     } else {
         return new \Enimiste\Math\VO\IntegerNumber($value);
     }
 }
开发者ID:enimiste,项目名称:l5-math,代码行数:15,代码来源:Helpers.php

示例6: formatPercentage

 /**
  * @param int|float $amount
  * @param int       $percentage
  *
  * @return float|int
  */
 public function formatPercentage($amount, $percentage = 0)
 {
     if ($percentage > 0) {
         if ($amount instanceof Money) {
             return $amount->multiply($percentage);
         }
         return $amount * $percentage;
     }
     return 0;
 }
开发者ID:Codixis,项目名称:CSBill,代码行数:16,代码来源:GlobalExtension.php

示例7: money

 /**
  * money
  *
  * @param float|\browner12\money\Money $money
  * @param string                       $currency
  * @return string
  */
 function money($money, $currency = 'usd')
 {
     //money object
     if ($money instanceof \browner12\money\Money) {
         $currency = $money->getCurrency()->currency();
         $money = $money->value();
     }
     //formatter
     $cf = new NumberFormatter('eng', NumberFormatter::CURRENCY);
     //return
     return $cf->formatCurrency($money, $currency);
 }
开发者ID:browner12,项目名称:helpers,代码行数:19,代码来源:money.php

示例8: testResponseConditionMatchCorrect

    /**
     * @dataProvider responseConditionMatchCorrectProvider
     * 
     * @param string $response A QTI Identifier
     * @param float $expectedScore The expected score for a given $response
     */
    public function testResponseConditionMatchCorrect($response, $expectedScore)
    {
        $rule = $this->createComponentFromXml('
			<responseCondition>
				<responseIf>
					<match>
						<variable identifier="RESPONSE"/>
						<correct identifier="RESPONSE"/>
					</match>
					<setOutcomeValue identifier="SCORE">
						<baseValue baseType="float">1</baseValue>
						</setOutcomeValue>
				</responseIf>
				<responseElse>
					<setOutcomeValue identifier="SCORE">
						<baseValue baseType="float">0</baseValue>
					</setOutcomeValue>
				</responseElse>
			</responseCondition>
		');
        $responseVarDeclaration = $this->createComponentFromXml('
			<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier">
				<correctResponse>
					<value>ChoiceA</value>
				</correctResponse>
			</responseDeclaration>
		');
        $responseVar = ResponseVariable::createFromDataModel($responseVarDeclaration);
        $this->assertTrue($responseVar->getCorrectResponse()->equals(new Identifier('ChoiceA')));
        // Set 'ChoiceA' to 'RESPONSE' in order to get a score of 1.0.
        $responseVar->setValue($response);
        $outcomeVarDeclaration = $this->createComponentFromXml('
			<outcomeDeclaration identifier="SCORE" cardinality="single" baseType="float">
				<defaultValue>
					<value>0</value>
				</defaultValue>
			</outcomeDeclaration>		
		');
        $outcomeVar = OutcomeVariable::createFromDataModel($outcomeVarDeclaration);
        $this->assertEquals(0, $outcomeVar->getDefaultValue()->getValue());
        $state = new State(array($responseVar, $outcomeVar));
        $processor = new ResponseConditionProcessor($rule);
        $processor->setState($state);
        $processor->process();
        $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $state['SCORE']);
        $this->assertTrue($expectedScore->equals($state['SCORE']));
    }
开发者ID:hutnikau,项目名称:qti-sdk,代码行数:53,代码来源:ResponseConditionProcessorTest.php

示例9: addCustomOptionsToBuyRequest

 /**
  * Add custom options to buy request.
  *
  * @param CartItemInterface $cartItem
  * @param \Magento\Framework\DataObject|float $params
  * @return \Magento\Framework\DataObject|float
  */
 private function addCustomOptionsToBuyRequest(CartItemInterface $cartItem, $params)
 {
     if (isset($this->cartItemProcessors['custom_options'])) {
         $buyRequestUpdate = $this->cartItemProcessors['custom_options']->convertToBuyRequest($cartItem);
         if (!$buyRequestUpdate) {
             return $params;
         }
         if ($params instanceof \Magento\Framework\DataObject) {
             $buyRequestUpdate->addData($params->getData());
         } else {
             if (is_numeric($params)) {
                 $buyRequestUpdate->setData('qty', $params);
             }
         }
         return $buyRequestUpdate;
     }
     return $params;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:25,代码来源:CartItemOptionsProcessor.php

示例10: renderText

 /**
  * Render text depending of font type and available font extensions
  * 
  * @param string $id 
  * @param string $text 
  * @param string $font 
  * @param ezcGraphColor $color 
  * @param ezcGraphCoordinate $position 
  * @param float $size 
  * @param float $rotation 
  * @return void
  */
 protected function renderText($text, $font, ezcGraphColor $color, ezcGraphCoordinate $position, $size, $rotation = null)
 {
     cairo_select_font_face($this->context, $font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
     cairo_set_font_size($this->context, $size);
     // Store current state of context
     cairo_save($this->context);
     cairo_move_to($this->context, 0, 0);
     if ($rotation !== null) {
         // Move to the center
         cairo_translate($this->context, $rotation->getCenter()->x, $rotation->getCenter()->y);
         // Rotate around text center
         cairo_rotate($this->context, deg2rad($rotation->getRotation()));
         // Center the text
         cairo_translate($this->context, $position->x - $rotation->getCenter()->x, $position->y - $rotation->getCenter()->y - $size * 0.15);
     } else {
         cairo_translate($this->context, $position->x, $position->y - $size * 0.15);
     }
     cairo_new_path($this->context);
     $this->getStyle($color, true);
     cairo_show_text($this->context, $text);
     cairo_stroke($this->context);
     // Restore state of context
     cairo_restore($this->context);
 }
开发者ID:jordanmanning,项目名称:ezpublish,代码行数:36,代码来源:cairo.php

示例11: valueToNumber

 /**
  * @param self|int|string|float $arg
  * @throws InvalidArgumentException
  * @return int|float
  */
 protected function valueToNumber($arg)
 {
     if ($arg instanceof self) {
         return $arg->toInt();
     }
     return Math::parseNumber($arg);
 }
开发者ID:kdyby,项目名称:money,代码行数:12,代码来源:Integer.php

示例12: renderText

 /**
  * Render text depending of font type and available font extensions
  * 
  * @param string $id 
  * @param string $text 
  * @param string $chars 
  * @param int $type 
  * @param string $path 
  * @param ezcGraphColor $color 
  * @param ezcGraphCoordinate $position 
  * @param float $size 
  * @param float $rotation 
  * @return void
  */
 protected function renderText($id, $text, $chars, $type, $path, ezcGraphColor $color, ezcGraphCoordinate $position, $size, $rotation = null)
 {
     $movie = $this->getDocument();
     $tb = new SWFTextField(SWFTEXTFIELD_NOEDIT);
     $tb->setFont(new SWFFont($path));
     $tb->setHeight($size);
     $tb->setColor($color->red, $color->green, $color->blue, 255 - $color->alpha);
     $tb->addString($text);
     $tb->addChars($chars);
     $object = $movie->add($tb);
     $object->rotate($rotation !== null ? -$rotation->getRotation() : 0);
     $object->moveTo($position->x + ($rotation === null ? 0 : $this->modifyCoordinate($rotation->get(0, 2))), $position->y - $size * (1 + $this->options->lineSpacing) + ($rotation === null ? 0 : $this->modifyCoordinate($rotation->get(1, 2))));
     $object->setName($id);
 }
开发者ID:jordanmanning,项目名称:ezpublish,代码行数:28,代码来源:flash.php

示例13: direct

 /**
  * Ceil a float
  * 
  * @param \Scalar\Float $float eg 13.22222
  * @return float eg 14.0
  */
 public function direct(float $float)
 {
     return ceil($float->getValue());
 }
开发者ID:void-sector,项目名称:scalar-objects,代码行数:10,代码来源:Ceil.php

示例14: toArray

 public function toArray()
 {
     $queryArr = $this->query->toArray();
     $queryParam = reset($queryArr);
     $first_key = key($queryArr);
     $query = ["not" => [$first_key => $queryParam]];
     return $query;
 }
开发者ID:neokike,项目名称:laravel-elasticsearch-query-builder,代码行数:8,代码来源:NotQuery.php

示例15: instructions

    /**
     * Dump style to a string, which can be directly inserted into content stream
     *
     * @return string
     */
    public function instructions()
    {
        $instructions = '';

        if ($this->_fillColor !== null) {
            $instructions .= $this->_fillColor->instructions(false);
        }

        if ($this->_color !== null) {
            $instructions .= $this->_color->instructions(true);
        }

        if ($this->_lineWidth !== null) {
            $instructions .= $this->_lineWidth->toString() . " w\n";
        }

        if ($this->_lineDashingPattern !== null) {
            $dashPattern = new InternalType\ArrayObject();

            foreach ($this->_lineDashingPattern as $dashItem) {
                $dashElement = new InternalType\NumericObject($dashItem);
                $dashPattern->items[] = $dashElement;
            }

            $instructions .= $dashPattern->toString() . ' '
                           . $this->_lineDashingPhase->toString() . " d\n";
        }

        return $instructions;
    }
开发者ID:niallmccrudden,项目名称:zf2,代码行数:35,代码来源:Style.php


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