Here is something that you can do with PHP to solve the problem:
function string_to_float($foo){
if($foo*1==$foo && !empty($foo)){
return $foo*1;
} else {
return $foo;
}
}
string_to_float($row->some_decimal_field);
The real question is, Why do you need to convert the type of the decimal string? If you are trying to use it in math, php will make the conversion automatically for you. As a decimal string is equivalent to a float with the same value. Here is a simple test:
$foo = "1.2";
$bar = 1.2;
if($foo===$bar){
$equivalent = "is";
} else {
$equivalent = "is not";
}
print '"1.2" '.$equivalent.' equal to 1.2 in type and value<br />';
if($foo==$bar){
$equivalent = "is";
} else {
$equivalent = "is not";
}
print '"1.2" '.$equivalent.' equal to 1.2 in value<br />';
$foo = "1.2"*1;
$bar = 1.2;
if($foo===$bar){
$equivalent = "is";
} else {
$equivalent = "is not";
}
print '"1.2"*1 '.$equivalent.' equal to 1.2 in type and value<br />';
which will return:
"1.2" is not equal to 1.2 in type and value
"1.2" is equal to 1.2 in value
"1.2"*1 is equal to 1.2 in type and value