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

PHP is_float函数代码示例

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

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



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

示例1: testSetWeight

 public function testSetWeight()
 {
     $tag = new Tag\Item(array('title' => 'foo', 'weight' => 1));
     $tag->setWeight('10');
     $this->assertEquals(10.0, $tag->getWeight());
     $this->assertTrue(is_float($tag->getWeight()));
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:7,代码来源:ItemTest.php


示例2: format

 /**
  * Returns the given amount as a formatted string according to the
  * given currency.
  * IMPORTANT NOTE:
  * The amount must always be the smallest unit passed as a string
  * or int! It is a very bad idea to use float for monetary
  * calculations if you need exact values, therefore
  * this method won't accept float values.
  * Examples:
  *      format (500, 'EUR');      --> '5,00 EUR'
  *      format (4.23, 'EUR');     --> FALSE
  *      format ('872331', 'EUR'); --> '8.723,31 EUR'.
  *
  * @param int|string $amount Amount to be formatted. Must be the smalles unit
  * @param string $currencyKey ISO 3 letter code of the currency
  * @param bool $withSymbol If set the currency symbol will be rendered
  *
  * @return string|bool String representation of the amount including currency
  *      symbol(s) or FALSE if $amount was of the type float
  */
 public static function format($amount, $currencyKey, $withSymbol = true)
 {
     if (is_float($amount)) {
         return false;
     }
     /**
      * Currency repository.
      *
      * @var CurrencyRepository
      */
     $currencyRepository = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Domain\\Repository\\CurrencyRepository');
     $currency = $currencyRepository->findByIso3($currencyKey);
     if (empty($currency)) {
         return false;
     }
     $formattedAmount = number_format($amount / $currency['cu_sub_divisor'], $currency['cu_decimal_digits'], $currency['cu_decimal_point'], $currency['cu_thousands_point']);
     if ($withSymbol) {
         $wholeString = $formattedAmount;
         if (!empty($currency['cu_symbol_left'])) {
             $wholeString = $currency['cu_symbol_left'] . ' ' . $wholeString;
         }
         if (!empty($currency['cu_symbol_right'])) {
             $wholeString .= ' ' . $currency['cu_symbol_right'];
         }
     } else {
         $wholeString = $formattedAmount;
     }
     return $wholeString;
 }
开发者ID:BenjaminBeck,项目名称:commerce,代码行数:49,代码来源:Money.php


示例3: fromStandardUnit

 /**
  * converts a value from the standard unit for the dimension to this unit.
  */
 public function fromStandardUnit($value)
 {
     if (!is_float($value)) {
         throw new \Exception('value must be a float');
     }
     return $value * $this->divisor;
 }
开发者ID:ljarray,项目名称:dbpedia,代码行数:10,代码来源:DivisorUnitDataType.php


示例4: getScalarTypeFromValue

 /**
  * Determines the type of a scalar value
  * @param mixed The scalar value
  * @return string The type of the scalar value
  */
 function getScalarTypeFromValue(&$value)
 {
     require_once DOM_XMLRPC_INCLUDE_PATH . 'dom_xmlrpc_constants.php';
     if (is_string($value)) {
         return DOM_XMLRPC_TYPE_STRING;
     } else {
         if (is_int($value)) {
             return DOM_XMLRPC_TYPE_INT;
         } else {
             if (is_float($value)) {
                 return DOM_XMLRPC_TYPE_DOUBLE;
             } else {
                 if (is_bool($value)) {
                     return DOM_XMLRPC_TYPE_BOOLEAN;
                 } else {
                     if (is_object($value)) {
                         require_once DOM_XMLRPC_INCLUDE_PATH . 'dom_xmlrpc_datetime_iso8601.php';
                         require_once DOM_XMLRPC_INCLUDE_PATH . 'dom_xmlrpc_base64.php';
                         if (get_class($value) == 'dom_xmlrpc_datetime_iso8601') {
                             return DOM_XMLRPC_TYPE_DATETIME;
                         } else {
                             if (get_class($value) == 'dom_xmlrpc_base64') {
                                 return DOM_XMLRPC_TYPE_BASE64;
                             }
                         }
                     }
                 }
             }
         }
     }
     return '';
 }
开发者ID:jwest00724,项目名称:mambo,代码行数:37,代码来源:dom_xmlrpc_utilities.php


示例5: serializeValue

 public static function serializeValue($value)
 {
     if ($value === null) {
         return 'null';
     } elseif ($value === false) {
         return 'false';
     } elseif ($value === true) {
         return 'true';
     } elseif (is_float($value) && (int) $value == $value) {
         return $value . '.0';
     } elseif (is_object($value) || gettype($value) == 'object') {
         return 'Object ' . get_class($value);
     } elseif (is_resource($value)) {
         return 'Resource ' . get_resource_type($value);
     } elseif (is_array($value)) {
         return 'Array of length ' . count($value);
     } elseif (is_integer($value)) {
         return (int) $value;
     } else {
         $value = (string) $value;
         if (function_exists('mb_convert_encoding')) {
             $value = mb_convert_encoding($value, 'UTF-8', 'UTF-8');
         }
         return $value;
     }
 }
开发者ID:dparks-seattletimes,项目名称:openworldstudios,代码行数:26,代码来源:Serializer.php


示例6: appendValue

 public function appendValue($value)
 {
     if (is_null($value)) {
         $this->append('null');
     } elseif (is_string($value)) {
         $this->_toPhpSyntax($value);
     } elseif (is_float($value)) {
         $this->append('<');
         $this->append($value);
         $this->append('F>');
     } elseif (is_bool($value)) {
         $this->append('<');
         $this->append($value ? 'true' : 'false');
         $this->append('>');
     } elseif (is_array($value) || $value instanceof \Iterator || $value instanceof \IteratorAggregate) {
         $this->appendValueList('[', ', ', ']', $value);
     } elseif (is_object($value) && !method_exists($value, '__toString')) {
         $this->append('<');
         $this->append(get_class($value));
         $this->append('>');
     } else {
         $this->append('<');
         $this->append($value);
         $this->append('>');
     }
     return $this;
 }
开发者ID:ngitimfoyo,项目名称:Nyari-AppPHP,代码行数:27,代码来源:BaseDescription.php


示例7: setOutputGamma

 /**
  * Sets the ouput gamma
  *
  * @param float
  */
 public function setOutputGamma($gamma)
 {
     if (is_float($gamma)) {
         $this->ouput_gamma = (double) $gamma;
         return true;
     }
 }
开发者ID:valerio-bozzolan,项目名称:openparlamento,代码行数:12,代码来源:sfImageGammaGD.class.php


示例8: __construct

 /** Constructor
  *
  */
 public function __construct($value, $lang = null, $datatype = null)
 {
     if (EasyRdf_Utils::is_associative_array($value)) {
         $this->_value = isset($value['value']) ? $value['value'] : null;
         $this->_lang = isset($value['lang']) ? $value['lang'] : null;
         $this->_datatype = isset($value['datatype']) ? $value['datatype'] : null;
     } else {
         $this->_value = $value;
         $this->_lang = $lang ? $lang : null;
         $this->_datatype = $datatype ? $datatype : null;
     }
     // Automatic datatype selection
     if ($this->_datatype == null) {
         if (is_float($this->_value)) {
             $this->_datatype = 'xsd:decimal';
         } else {
             if (is_int($this->_value)) {
                 $this->_datatype = 'xsd:integer';
             } else {
                 if (is_bool($this->_value)) {
                     $this->_datatype = 'xsd:boolean';
                 }
             }
         }
     }
     // Expand shortened URIs (qnames)
     if ($this->_datatype) {
         $this->_datatype = EasyRdf_Namespace::expand($this->_datatype);
     }
 }
开发者ID:nhukhanhdl,项目名称:easyrdf,代码行数:33,代码来源:Literal.php


示例9: setAzureProperty

 /**
  * Set an Azure property
  *
  * @param string $name  Property name
  * @param mixed  $value Property value
  * @param string $type  Property type (Edm.xxxx)
  * @return DynamicTableEntity
  */
 public function setAzureProperty($name, $value = '', $type = null)
 {
     if (strtolower($name) == 'partitionkey') {
         $this->setPartitionKey($value);
     } elseif (strtolower($name) == 'rowkey') {
         $this->setRowKey($value);
     } elseif (strtolower($name) == 'etag') {
         $this->setEtag($value);
     } else {
         if (!array_key_exists(strtolower($name), $this->_dynamicProperties)) {
             // Determine type?
             if ($type === null) {
                 $type = 'Edm.String';
                 if (is_int($value)) {
                     $type = 'Edm.Int32';
                 } elseif (is_float($value)) {
                     $type = 'Edm.Double';
                 } elseif (is_bool($value)) {
                     $type = 'Edm.Boolean';
                 }
             }
             // Set dynamic property
             $this->_dynamicProperties[strtolower($name)] = (object) array('Name' => $name, 'Type' => $type, 'Value' => $value);
         }
         $this->_dynamicProperties[strtolower($name)]->Value = $value;
     }
     return $this;
 }
开发者ID:robertodormepoco,项目名称:zf2,代码行数:36,代码来源:DynamicTableEntity.php


示例10: toCents

 /**
  * convert a money amount (represented by a float or string (based on locale) ie.: R$ 5,00) to cents (represented by an int).
  *
  * @param float $amount
  *
  * @throws \UnexpectedValueException
  *
  * @return int
  */
 public static function toCents($amount)
 {
     /*
      * There's probably a better way, but this is what i could come up with
      * to avoid rounding errors
      * todo: search for a better way
      */
     if (!is_float($amount)) {
         $type = gettype($amount);
         throw new \UnexpectedValueException("Needs a float! not {$type}");
     }
     //handle locales
     $locale = localeconv();
     $amount = str_replace($locale['mon_thousands_sep'], '', $amount);
     $amount = str_replace($locale['mon_decimal_point'], '.', $amount);
     $amount = str_replace($locale['decimal_point'], '.', $amount);
     $parts = explode('.', "{$amount}");
     // handle the case where $amount has a .0 fraction part
     if (count($parts) == 1) {
         $parts[] = '00';
     }
     list($whole, $fraction) = $parts;
     /*
      * since the documentation only mentions decimals with a precision of two
      * and doesn't specify any rounding method i'm truncating the number
      *
      * the str_pad is to handle the case where $amount is, for example, 6.9
      */
     $fraction = str_pad(substr($fraction, 0, 2), 2, '0');
     $whole = (int) $whole * 100;
     $fraction = (int) $fraction;
     return $whole + $fraction;
 }
开发者ID:moip,项目名称:moip-sdk-php,代码行数:42,代码来源:Utils.php


示例11: __construct

 /**
  * Constructor.
  *
  * @param array $index Index specification
  */
 public function __construct(array $index)
 {
     if (!isset($index['key'])) {
         throw new InvalidArgumentException('Required "key" document is missing from index specification');
     }
     if (!is_array($index['key']) && !is_object($index['key'])) {
         throw new InvalidArgumentTypeException('"key" option', $index['key'], 'array or object');
     }
     foreach ($index['key'] as $fieldName => $order) {
         if (!is_int($order) && !is_float($order) && !is_string($order)) {
             throw new InvalidArgumentTypeException(sprintf('order value for "%s" field within "key" option', $fieldName), $order, 'numeric or string');
         }
     }
     if (!isset($index['ns'])) {
         throw new InvalidArgumentException('Required "ns" option is missing from index specification');
     }
     if (!is_string($index['ns'])) {
         throw new InvalidArgumentTypeException('"ns" option', $index['ns'], 'string');
     }
     if (!isset($index['name'])) {
         $index['name'] = \MongoDB\generate_index_name($index['key']);
     }
     if (!is_string($index['name'])) {
         throw new InvalidArgumentTypeException('"name" option', $index['name'], 'string');
     }
     $this->index = $index;
 }
开发者ID:roquie,项目名称:mongo-php-library,代码行数:32,代码来源:IndexInput.php


示例12: clean_var_info

/**
 * This function will return clean variable info
 *
 * @param mixed $var
 * @param string $indent Indent is used when dumping arrays recursivly
 * @param string $indent_close_bracet Indent close bracket param is used
 *   internaly for array output. It is shorter that var indent for 2 spaces
 * @return null
 */
function clean_var_info($var, $indent = '&nbsp;&nbsp;', $indent_close_bracet = '')
{
    if (is_object($var)) {
        return 'Object (class: ' . get_class($var) . ')';
    } elseif (is_resource($var)) {
        return 'Resource (type: ' . get_resource_type($var) . ')';
    } elseif (is_array($var)) {
        $result = 'Array (';
        if (count($var)) {
            foreach ($var as $k => $v) {
                $k_for_display = is_integer($k) ? $k : "'" . clean($k) . "'";
                $result .= "\n" . $indent . '[' . $k_for_display . '] => ' . clean_var_info($v, $indent . '&nbsp;&nbsp;', $indent_close_bracet . $indent);
            }
            // foreach
        }
        // if
        return $result . "\n{$indent_close_bracet})";
    } elseif (is_int($var)) {
        return '(int)' . $var;
    } elseif (is_float($var)) {
        return '(float)' . $var;
    } elseif (is_bool($var)) {
        return $var ? 'true' : 'false';
    } elseif (is_null($var)) {
        return 'NULL';
    } else {
        return "(string) '" . clean($var) . "'";
    }
    // if
}
开发者ID:pnagaraju25,项目名称:fengoffice,代码行数:39,代码来源:general.php


示例13: __construct

 /**
  * @param integer $value The max value for comparison
  */
 public function __construct($value = null)
 {
     if ($value === null || !is_int($value) && !is_float($value)) {
         throw new InvalidArgumentException("invalid value provided for 'value'; " . "expecting an integer or a float");
     }
     $this->max = $value;
 }
开发者ID:GenomeUS,项目名称:sndsgd-field,代码行数:10,代码来源:MaxValueRule.php


示例14: __construct

 public function __construct($arg1, $arg2 = null)
 {
     if (is_object($arg1) && is_null($arg2)) {
         if (!is_a($arg1, 'midgard_object')) {
             throw new InvalidArgumentException("You can instantiate spots only from MgdSchema objects");
         }
         $this->latitude = $arg1->latitude;
         $this->longitude = $arg1->longitude;
         if (isset($arg1->accuracy)) {
             $this->accuracy = $arg1->accuracy;
         }
         $this->when = $arg1->metadata->created;
     } elseif (is_string($arg1) && is_null($arg2)) {
         $this->text = $arg1;
         $this->accuracy = 80;
     } else {
         if (!is_float($arg1) || !is_float($arg2)) {
             throw new InvalidArgumentException("A pair of WGS-84 coordinates expected");
         }
         $this->latitude = $arg1;
         $this->longitude = $arg2;
     }
     if ($this->latitude > 90 || $this->latitude < -90) {
         throw new InvalidArgumentException("WGS-84 latitude must be between 90 and -90 degrees");
     }
     if ($this->longitude > 180 || $this->longitude < -180) {
         throw new InvalidArgumentException("WGS-84 longitude must be between 180 and -180 degrees");
     }
 }
开发者ID:bergie,项目名称:midgardmvc_helper_location,代码行数:29,代码来源:spot.php


示例15: isValid

 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if $value is a valid integer
  *
  * @param  string|integer $value
  * @return boolean
  */
 public function isValid($value)
 {
     if (!is_string($value) && !is_int($value) && !is_float($value)) {
         $this->error(self::INVALID);
         return false;
     }
     if (is_int($value)) {
         return true;
     }
     $this->setValue($value);
     if ($this->locale === null) {
         $locale = localeconv();
         $valueFiltered = str_replace($locale['decimal_point'], '.', $value);
         $valueFiltered = str_replace($locale['thousands_sep'], '', $valueFiltered);
         if (strval(intval($valueFiltered)) != $valueFiltered) {
             $this->error(self::NOT_INT);
             return false;
         }
     } else {
         try {
             if (!Zend_Locale_Format::isInteger($value, ['locale' => $this->locale])) {
                 $this->error(self::NOT_INT);
                 return false;
             }
         } catch (Zend_Locale_Exception $e) {
             $this->error(self::NOT_INT);
             return false;
         }
     }
     return true;
 }
开发者ID:argentinaluiz,项目名称:js_zf2_library,代码行数:39,代码来源:JSInt.php


示例16: mypercentile

 function mypercentile($X, $percentile)
 {
     if (0 < $percentile && $percentile < 1) {
         $p = $percentile;
     } else {
         if (1 < $percentile && $percentile <= 100) {
             $p = $percentile * 0.01;
         } else {
             return "";
         }
     }
     $count = count($X);
     $allindex = ($count - 1) * $p;
     $intvalindex = intval($allindex);
     $floatval = $allindex - $intvalindex;
     sort($X);
     if (!is_float($floatval)) {
         $result = $X[$intvalindex];
     } else {
         if ($count > $intvalindex + 1) {
             $result = $floatval * ($X[$intvalindex + 1] - $X[$intvalindex]) + $X[$intvalindex];
         } else {
             $result = $X[$intvalindex];
         }
     }
     return $result;
 }
开发者ID:chemaveba,项目名称:VisLabData,代码行数:27,代码来源:SchemA.php


示例17: isValid

 /**
  * (non-PHPdoc)
  * @see IValidator::isValid()
  */
 public function isValid($val)
 {
     $this->val = $val;
     $ereg = '/^' . $this->type . '$/i';
     if (preg_match($ereg, 'int') || preg_match($ereg, 'integer')) {
         $state = is_int($val);
     } else {
         if (preg_match($ereg, 'float')) {
             $state = is_float($val);
         } else {
             if (preg_match($ereg, 'string')) {
                 $state = is_string($val);
             } else {
                 if (preg_match($ereg, 'array')) {
                     $state = is_array($val);
                 } else {
                     if (preg_match($ereg, 'bool')) {
                         $state = is_bool($val);
                     } else {
                         if (preg_match($ereg, 'null')) {
                             $state = is_null($val);
                         }
                     }
                 }
             }
         }
     }
     if ($state === false) {
         throw new TypeException($this->val, $this->type);
         return false;
     }
     return true;
 }
开发者ID:syamgot,项目名称:php-validator,代码行数:37,代码来源:TypeValidator.php


示例18: isValid

 /**
  * Returns true if and only if $value is a valid integer
  *
  * @param  string|int $value
  * @return bool
  * @throws Exception\InvalidArgumentException
  */
 public function isValid($value)
 {
     if (!is_string($value) && !is_int($value) && !is_float($value)) {
         $this->error(self::INVALID);
         return false;
     }
     if (is_int($value)) {
         return true;
     }
     $this->setValue($value);
     $locale = $this->getLocale();
     $format = new NumberFormatter($locale, NumberFormatter::DECIMAL);
     if (intl_is_failure($format->getErrorCode())) {
         throw new Exception\InvalidArgumentException("Invalid locale string given");
     }
     $parsedInt = $format->parse($value, NumberFormatter::TYPE_INT64);
     if (intl_is_failure($format->getErrorCode())) {
         $this->error(self::NOT_INT);
         return false;
     }
     $decimalSep = $format->getSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
     $groupingSep = $format->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL);
     $valueFiltered = str_replace($groupingSep, '', $value);
     $valueFiltered = str_replace($decimalSep, '.', $valueFiltered);
     if (strval($parsedInt) !== $valueFiltered) {
         $this->error(self::NOT_INT);
         return false;
     }
     return true;
 }
开发者ID:tejdeeps,项目名称:tejcs.com,代码行数:37,代码来源:Int.php


示例19: _formatVar

 function _formatVar(&$value)
 {
     if (is_null($value)) {
         return Artx_Log_Formatter::_formatNull($value);
     }
     if (is_bool($value)) {
         return Artx_Log_Formatter::_formatBool($value);
     }
     if (is_int($value) || is_float($value)) {
         return $value;
     }
     if (is_object($value)) {
         return Artx_Log_Formatter::_formatObject($value);
     }
     // is_callable should be placed before is_string and is_array:
     if (is_callable($value)) {
         return Artx_Log_Formatter::_formatCallback($value);
     }
     if (is_string($value)) {
         return Artx_Log_Formatter::_formatString($value);
     }
     if (is_array($value)) {
         return Artx_Log_Formatter::_formatArray($value);
     }
     return gettype($value) . ' { ... }';
 }
开发者ID:sealse,项目名称:mondiale,代码行数:26,代码来源:Formatter.php


示例20: formatValue

 private function formatValue($value)
 {
     if (is_string($value)) {
         if (strlen($value) > 20) {
             $this->remaining[] = $value;
             return '?';
         } else {
             return $this->connection->quote($value);
         }
     } elseif (is_int($value)) {
         return (string) $value;
     } elseif (is_float($value)) {
         return rtrim(rtrim(number_format($value, 10, '.', ''), '0'), '.');
     } elseif (is_bool($value)) {
         return $this->driver->formatBool($value);
     } elseif ($value === NULL) {
         return 'NULL';
     } elseif ($value instanceof Table\ActiveRow) {
         return $value->getPrimary();
     } elseif (is_array($value) || $value instanceof \Traversable) {
         $vx = $kx = array();
         if ($value instanceof \Traversable) {
             $value = iterator_to_array($value);
         }
         if (isset($value[0])) {
             // non-associative; value, value, value
             foreach ($value as $v) {
                 $vx[] = $this->formatValue($v);
             }
             return implode(', ', $vx);
         } elseif ($this->arrayMode === 'values') {
             // (key, key, ...) VALUES (value, value, ...)
             $this->arrayMode = 'multi';
             foreach ($value as $k => $v) {
                 $kx[] = $this->driver->delimite($k);
                 $vx[] = $this->formatValue($v);
             }
             return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
         } elseif ($this->arrayMode === 'assoc') {
             // key=value, key=value, ...
             foreach ($value as $k => $v) {
                 $vx[] = $this->driver->delimite($k) . '=' . $this->formatValue($v);
             }
             return implode(', ', $vx);
         } elseif ($this->arrayMode === 'multi') {
             // multiple insert (value, value, ...), ...
             foreach ($value as $v) {
                 $vx[] = $this->formatValue($v);
             }
             return '(' . implode(', ', $vx) . ')';
         }
     } elseif ($value instanceof \DateTime) {
         return $this->driver->formatDateTime($value);
     } elseif ($value instanceof SqlLiteral) {
         return $value->__toString();
     } else {
         $this->remaining[] = $value;
         return '?';
     }
 }
开发者ID:svobodni,项目名称:web,代码行数:60,代码来源:SqlPreprocessor.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP is_foreachable函数代码示例发布时间:2022-05-15
下一篇:
PHP is_finite函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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