5

EDIT: This was just confirmed as a bug in Doctrine 2 http://www.doctrine-project.org/jira/browse/DDC-1112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15724#action_15724


I have a Doctrine 2 entity and the value is mapped like this (with regular getter/setter):

/**
 * @Column(type="decimal", precision=40, scale=30)
 */
protected $someValue;

/**
 * @return decimal
 */
public function getSomeValue()
{
    return $this->someValue;
}

/**
 * @param decimal $someValue
 */
public function setSomeValue($someValue)
{
    $this->someValue = $someValue;
}

When I set that value from my code, the value gets written into the database correctly. But, and that is my problem, when I get the value (via getter or \Doctrine\Common\Util\Debug::dump()), it always gives me a number with maximum 14 digits, and it rounds the value. I read the record with the default findById().

eg: with value 1234567890.012345678901234567890123456789 I have 1234567890.0123
eg: with value 890.0123456789012345678901234567890123456 I have 890.01234567890

I of course want all digits, not just 14. The field in MySQL is declared like this:

someValue decimal(40,30) NOT NULL,

When I get the value with raw PHP and mysql_query(), it returns correctly.

Edit: seems like the problem is that Doctrine returns a float:

["someValue":protected]=> float(234567890.01235)

What's wrong, what should I check next, how to fix, any clues?

tvlooy
  • 1,036
  • 10
  • 16

1 Answers1

1

It sounds like Doctrine2 is returning the float value and is running into floating point precision while mysql_query() is returning the value as a string. You can do a var_dump() on each returned variable and see the scalar type.

Paul DelRe
  • 4,003
  • 1
  • 24
  • 26
  • seems like it indeed returns a float: ["someValue":protected]=> float(234567890.01235) is that something I did wrong or how do I fix this? – tvlooy Apr 12 '11 at 13:06
  • If you are simply going to display the number, there might be a way to have Doctrine return the value as a string but I don't know Doctrine. If you are going to be doing math, you could either round it to a known level of precision. There is a setting in the ini file you could change to increase the digits of [precision](http://us3.php.net/manual/en/ini.core.php#ini.precision), but there is always a limit. A better explaination can be found [here](http://stackoverflow.com/questions/3726721/php-math-precision). – Paul DelRe Apr 12 '11 at 13:30
  • confirmed as a bug, hope they fix it soon, thanks for your input! – tvlooy Apr 12 '11 at 14:19