本文整理匯總了PHP中SpoonFilter::isFloat方法的典型用法代碼示例。如果您正苦於以下問題:PHP SpoonFilter::isFloat方法的具體用法?PHP SpoonFilter::isFloat怎麽用?PHP SpoonFilter::isFloat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SpoonFilter
的用法示例。
在下文中一共展示了SpoonFilter::isFloat方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testIsFloat
public function testIsFloat()
{
$this->assertTrue(SpoonFilter::isFloat(1));
$this->assertFalse(SpoonFilter::isFloat('a'));
$this->assertTrue(SpoonFilter::isFloat(10000000000.0));
$this->assertFalse(SpoonFilter::isFloat('1e10'));
$this->assertFalse(SpoonFilter::isFloat('1a10'));
$this->assertTrue(SpoonFilter::isFloat(1.337));
$this->assertTrue(SpoonFilter::isFloat(-1.337));
$this->assertTrue(SpoonFilter::isFloat(100));
$this->assertTrue(SpoonFilter::isFloat(-100));
$this->assertFalse(SpoonFilter::isFloat('1.,35'));
$this->assertFalse(SpoonFilter::isFloat('1,.35'));
$this->assertTrue(SpoonFilter::isFloat('1,35', true));
$this->assertTrue(SpoonFilter::isFloat('-1,35', true));
$this->assertTrue(SpoonFilter::isFloat(65.0, true));
$this->assertTrue(SpoonFilter::isFloat('65.00'));
$this->assertTrue(SpoonFilter::isFloat(65.01000000000001, true));
$this->assertTrue(SpoonFilter::isFloat('65.010', true));
$this->assertFalse(SpoonFilter::isFloat(array()));
}
示例2: isFloat
/**
* Checks this field for numbers 0-9 and an optional - (minus) sign (in the beginning only).
*
* @return bool
* @param string[optional] $error The error message to set.
* @param bool[optional] $allowCommas Do you want to use commas as a decimal separator?
*/
public function isFloat($error = null, $allowCommas = false)
{
// filled
if ($this->isFilled()) {
// post/get data
$data = $this->getMethod(true);
// validate
if (!isset($data[$this->attributes['name']]) || !SpoonFilter::isFloat($data[$this->attributes['name']], $allowCommas)) {
if ($error !== null) {
$this->setError($error);
}
return false;
}
return true;
}
// not submitted
if ($error !== null) {
$this->setError($error);
}
return false;
}