本文整理汇总了PHP中is_float函数的典型用法代码示例。如果您正苦于以下问题:PHP is_float函数的具体用法?PHP is_float怎么用?PHP is_float使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_float函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()));
}
示例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;
}
示例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;
}
示例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 '';
}
示例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;
}
}
示例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;
}
示例7: setOutputGamma
/**
* Sets the ouput gamma
*
* @param float
*/
public function setOutputGamma($gamma)
{
if (is_float($gamma)) {
$this->ouput_gamma = (double) $gamma;
return true;
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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 = ' ', $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 . ' ', $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
}
示例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;
}
示例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");
}
}
示例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;
}