本文整理汇总了PHP中jDb::floatToStr方法的典型用法代码示例。如果您正苦于以下问题:PHP jDb::floatToStr方法的具体用法?PHP jDb::floatToStr怎么用?PHP jDb::floatToStr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jDb
的用法示例。
在下文中一共展示了jDb::floatToStr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFloatToStr
function testFloatToStr()
{
$this->assertEqual('12', jDb::floatToStr(12));
$this->assertEqual('12.56', jDb::floatToStr(12.56));
$this->assertEqual('12', jDb::floatToStr("12"));
$this->assertEqual('12.56', jDb::floatToStr("12.56"));
$this->assertEqual('65.78E6', jDb::floatToStr("65.78E6"));
$this->assertEqual('65.78E6', jDb::floatToStr(65780000.0));
$this->assertEqual('65.78E42', jDb::floatToStr(6.578E+43));
// not very good behavior, but this is the behavior in old stable version of jelix
$this->assertEqual('65', jDb::floatToStr("65,650.98"));
$this->assertEqual('12', jDb::floatToStr("12,589"));
// ',' no allowed as decimal separator
$this->assertEqual('96', jDb::floatToStr("96 000,98"));
// some test to detect if the behavior of PHP change
$this->assertFalse(is_numeric("65,650.98"));
$this->assertFalse(is_float("65,650.98"));
$this->assertFalse(is_integer("65,650.98"));
$this->assertEqual('65', floatval("65,650.98"));
}
示例2: _prepareValue
/**
* prepare the value ready to be used in a dynamic evaluation
*/
protected final function _prepareValue($value, $fieldType, $notNull = false)
{
if (!$notNull && $value === null) {
return 'NULL';
}
switch (strtolower($fieldType)) {
case 'integer':
return intval($value);
case 'double':
case 'float':
case 'numeric':
case 'decimal':
return jDb::floatToStr($value);
case 'boolean':
if ($value === true || strtolower($value) == 'true' || intval($value) === 1 || $value === 't' || $value === 'on') {
return $this->trueValue;
} else {
return $this->falseValue;
}
break;
default:
return $this->_conn->quote2($value, true, $fieldType == 'binary');
}
}
示例3: escapeValue
public function escapeValue($unifiedType, $value, $checkNull = false, $toPhpSource = false)
{
if ($checkNull && ($value === null || strtolower($value) == 'null')) {
return 'NULL';
}
switch ($this->unifiedToPHPType($unifiedType)) {
case 'boolean':
return $this->getBooleanValue($value);
case 'integer':
return (string) intval($value);
case 'float':
case 'numeric':
case 'decimal':
return jDb::floatToStr($value);
default:
if ($toPhpSource) {
if ($unifiedType == 'varbinary' || $unifiedType == 'binary') {
return '\'.$this->_conn->quote2(\'' . str_replace('\'', '\\\'', $value) . '\',true,true).\'';
} else {
if (strpos($value, "'") !== false) {
return '\'.$this->_conn->quote(\'' . str_replace('\'', '\\\'', $value) . '\').\'';
} else {
return "\\'" . $value . "\\'";
}
}
} elseif ($this->_conn) {
return $this->_conn->quote($value);
} else {
return "'" . addslashes($value) . "'";
}
}
}