[DBAL-180] Documentation states that Doctrine 'decimal' (DecimalType) is mapped to PHP 'double', however, string is returned Created: 11/Nov/11 Updated: 20/Dec/12
|Reporter:||Menno Holtkamp||Assignee:||Benjamin Eberlei|
"decimal: Type that maps an SQL DECIMAL to a PHP double."
However, in the commit history, we can see that the casting to a float is removed: https://github.com/doctrine/dbal/commits/master/lib/Doctrine/DBAL/Types/DecimalType.php. Casting to a double is not possible in PHP?This seems to result in a float as well, that is probably why it was removed.
I found this out when using PHP's 'is_double()' function (alias of is_float()) to check whether a decimal property was set or not.
Suggestion is to either:
In my check function I guess I will use the is_numeric() function.
|Comment by Roel Harbers [ 19/Mar/12 ]|
I would strongly suggest to leave the behaviour as-is, and fix the documentation, because of all the trouble associated with floating point and rounding. People use the DECIMAL type to prevent those issues, so having the ORM convert it to floating point again would be pretty bad.
|Comment by Patrick McDougle [ 26/Apr/12 ]|
I have submitted a pull request on this issue on github. Hopefully the doc will be updated soon so other people don't expect the wrong behavior!
Mods, this issue can probably be closed.
|Comment by Oleg Namaka [ 24/May/12 ]|
Leaving decimal values as strings creates another issue with unnecessary entity updates because old and new same values have different types: old value is always the string type, the new one - decimal. If an old value is '10.00' as a string and the new value is 10 decimal than Doctrine will issue the UPDATE statement for that entity. This is plainly wrong IMHO.
|Comment by karlie verkest [ 20/Dec/12 ]|
There may be other issues around comparison. I'd rather be comparing numeric types than strings when comparing "decimal" values.