• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP float类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了float类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: writeQTime

 /**
  * Writes a QTime for the given timestamp or DateTime object
  *
  * The QTime will only carry the number of milliseconds since midnight.
  * This means you should probably only use this for times within the current
  * day.
  *
  * If you pass a timestamp from any other day, it will write the number of
  * milliseconds that passed since that day's midnight. Note that reading
  * this number has no indication this is not the current day, so you're
  * likely going to lose the day information and may end up with wrong dates.
  *
  * The QTime will be sent as the number of milliseconds since midnight,
  * without any awareness of timezone or DST properties. Thus, writing this
  * will assume it is relative to the current timezone. This means that the
  * time "14:10:34.5108" will be 14h after midnight, irrespective of its
  * actual timezone. The receiving side may not be aware of your local
  * timezone, so it can only assume its own local timezone as a base.
  *
  * Make sure to use (i.e. convert via `setTimeZone()`) to the same timezone
  * on both sides or consider using the `writeQDateTime()` method instead,
  * which uses absolute time stamps and does not suffer from this.
  *
  * You can also pass a Unix timestamp to this function, this will be assumed
  * to be relative to the local midnight timestamp. If you need more control
  * over your timezone, consider passing a `DateTime` object instead.
  *
  * @param DateTime|float $timestamp
  * @see self::writeQDateTime
  */
 public function writeQTime($timestamp)
 {
     if ($timestamp instanceof \DateTime) {
         $msec = $timestamp->format('H') * 3600000 + $timestamp->format('i') * 60000 + $timestamp->format('s') * 1000 + (int) ($timestamp->format('0.u') * 1000);
     } else {
         $msec = round(($timestamp - strtotime('midnight', (int) $timestamp)) * 1000);
     }
     $this->writer->writeUInt32BE($msec);
 }
开发者ID:clue,项目名称:qdatastream,代码行数:39,代码来源:Writer.php


示例15: getVersionPreview

 /**
  * @see Object_Class_Data::getVersionPreview
  * @param float $data
  * @return float
  */
 public function getVersionPreview($data)
 {
     if ($data instanceof \Pimcore\Model\Object\Data\IndexFieldSelection) {
         return $data->getTenant() . " " . $data->getField() . " " . $data->getPreSelect();
     }
     return "";
 }
开发者ID:ascertain,项目名称:NGshop,代码行数:12,代码来源:IndexFieldSelection.php


示例16: _processPartialAuthorizationResponse

 /**
  * Set split_tender_id to quote payment if needed
  *
  * @param \Magento\Framework\Object $response
  * @param float $orderPayment
  * @throws \Magento\Payment\Model\Info\Exception
  * @return bool
  */
 protected function _processPartialAuthorizationResponse($response, $orderPayment)
 {
     if (!$response->getSplitTenderId()) {
         return false;
     }
     $quotePayment = $orderPayment->getOrder()->getQuote()->getPayment();
     $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_DECLINED);
     $exceptionMessage = null;
     try {
         switch ($response->getResponseCode()) {
             case self::RESPONSE_CODE_APPROVED:
                 $this->_registerCard($response, $orderPayment);
                 $this->_clearAssignedData($quotePayment);
                 $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_SUCCESS);
                 return true;
             case self::RESPONSE_CODE_HELD:
                 if ($response->getResponseReasonCode() != self::RESPONSE_REASON_CODE_PARTIAL_APPROVE) {
                     return false;
                 }
                 if ($this->getCardsStorage($orderPayment)->getCardsCount() + 1 >= self::PARTIAL_AUTH_CARDS_LIMIT) {
                     $this->cancelPartialAuthorization($orderPayment);
                     $this->_clearAssignedData($quotePayment);
                     $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_CARDS_LIMIT_EXCEEDED);
                     $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation());
                     $exceptionMessage = __('You have reached the maximum number of credit cards ' . 'allowed to be used for the payment.');
                     break;
                 }
                 $orderPayment->setAdditionalInformation($this->_splitTenderIdKey, $response->getSplitTenderId());
                 $this->_registerCard($response, $orderPayment);
                 $this->_clearAssignedData($quotePayment);
                 $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_SUCCESS);
                 $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation());
                 $exceptionMessage = null;
                 break;
             case self::RESPONSE_CODE_DECLINED:
             case self::RESPONSE_CODE_ERROR:
                 $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_DECLINED);
                 $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation());
                 $exceptionMessage = $this->_wrapGatewayError($response->getResponseReasonText());
                 break;
             default:
                 $this->setPartialAuthorizationLastActionState(self::PARTIAL_AUTH_LAST_DECLINED);
                 $quotePayment->setAdditionalInformation($orderPayment->getAdditionalInformation());
                 $exceptionMessage = $this->_wrapGatewayError(__('Something went wrong while authorizing the partial payment.'));
         }
     } catch (\Exception $e) {
         $exceptionMessage = $e->getMessage();
     }
     throw new \Magento\Payment\Model\Info\Exception($exceptionMessage);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:58,代码来源:Authorizenet.php


示例17: getVersionPreview

 /**
  * @see Object_Class_Data::getVersionPreview
  * @param float $data
  * @return float
  */
 public function getVersionPreview($data)
 {
     if ($data instanceof \Object_Data_QuantityValue) {
         return $data->getValue() . " " . $data->getUnit()->getAbbreviation();
     }
     return "";
 }
开发者ID:rolandstoll,项目名称:pimcore,代码行数:12,代码来源:QuantityValue.php


示例18: _exchangeCurrency

 /**
  * Internal method which calculates the exchanges currency
  *
  * @param float|integer|Zend\Currency\Currency $value    Compares the currency with this value
  * @param string|Zend\Currency\Currency        $currency The currency to compare this value from
  * @return float
  */
 protected function _exchangeCurrency($value, $currency)
 {
     if ($value instanceof Currency) {
         $currency = $value->getShortName();
         $value = $value->getValue();
     } else {
         $currency = $this->getShortName($currency, $this->getLocale());
     }
     $rate = 1;
     if ($currency !== $this->getShortName()) {
         $service = $this->getService();
         if (!$service instanceof CurrencyService) {
             throw new Exception\RuntimeException('No exchange service applied');
         }
         $rate = $service->getRate($currency, $this->getShortName());
     }
     $value *= $rate;
     return $value;
 }
开发者ID:nevvermind,项目名称:zf2,代码行数:26,代码来源:Currency.php


示例19: normalise_timezone

 /**
  * Normalise the timezone name. If timezone not supported
  * this method falls back to server timezone (if valid)
  * or default PHP timezone.
  *
  * @param int|string|float|DateTimeZone $tz
  * @return string timezone compatible with PHP
  */
 public static function normalise_timezone($tz)
 {
     global $CFG;
     if ($tz instanceof DateTimeZone) {
         return $tz->getName();
     }
     self::init_zones();
     $tz = (string) $tz;
     if (isset(self::$goodzones[$tz]) or isset(self::$bczones[$tz])) {
         return $tz;
     }
     $fixed = false;
     if (isset(self::$badzones[$tz])) {
         // Convert to known zone.
         $tz = self::$badzones[$tz];
         $fixed = true;
     } else {
         if (is_number($tz)) {
             // Half hour numeric offsets were already tested, try rounding to integers here.
             $roundedtz = (string) (int) $tz;
             if (isset(self::$badzones[$roundedtz])) {
                 $tz = self::$badzones[$roundedtz];
                 $fixed = true;
             }
         }
     }
     if ($fixed and isset(self::$goodzones[$tz]) or isset(self::$bczones[$tz])) {
         return $tz;
     }
     // Is server timezone usable?
     if (isset($CFG->timezone) and !is_numeric($CFG->timezone)) {
         $result = @timezone_open($CFG->timezone);
         // Hide notices if invalid.
         if ($result !== false) {
             return $result->getName();
         }
     }
     // Bad luck, use the php.ini default or value set in config.php.
     return self::get_default_php_timezone();
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:48,代码来源:date.php


示例20: 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)
 {
     $this->context->selectFontFace($font, CairoFontSlant::NORMAL, CairoFontWeight::NORMAL);
     $this->context->setFontSize($size);
     // Store current state of context
     $this->context->save();
     $this->context->moveTo(0, 0);
     if ($rotation !== null) {
         // Move to the center
         $this->context->translate($rotation->getCenter()->x, $rotation->getCenter()->y);
         // Rotate around text center
         $this->context->rotate(deg2rad($rotation->getRotation()));
         // Center the text
         $this->context->translate($position->x - $rotation->getCenter()->x, $position->y - $rotation->getCenter()->y - $size * 0.15);
     } else {
         $this->context->translate($position->x, $position->y - $size * 0.15);
     }
     $this->context->newPath();
     $this->getStyle($color, true);
     $this->context->showText($text);
     $this->context->stroke();
     // Restore state of context
     $this->context->restore();
 }
开发者ID:Adeelgill,项目名称:livehelperchat,代码行数:36,代码来源:cairo_oo.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP foo类代码示例发布时间:2022-05-23
下一篇:
PHP flexicontent_html类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap