I have an App in CakePHP 2.2 & MySQL. I noticed that the type casting of the value returned is string for many types like Float, Decimal, Int, Varchar, Text etc..:
Float or Decimal:
var_dump($this->field('field_name'));
string(4) "1.00"
Int
var_dump($this->field('field_name'));
string(1) "1"
This problem Not occur only using TINYINT(1) for boolean fields:
Tinyint(1)
var_dump($this->field('field_name'));
bool(true)
Normally for currency fields I set the field type as FLOAT or DECIMAL(11,2)... maybe Im wrong using this types in CakePHP? This behavior is very tedious especially with decimal fields because when the value is 0 is returned as string "0.00" that is true. So I have to always remember to force the type like this:
if((float)$this->field('price')){
....
}
Why CakePHP does not return values with the proper typecasting? How do I fix this? Thank you!