Permalink
Browse files

DBAL-121 - Do not convert decimals to float

  • Loading branch information...
1 parent dd7beb2 commit 9f51afa210d5c0165dfe6c622e07e42aa54c09fb @beberlei beberlei committed May 14, 2011
@@ -40,6 +40,6 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla
public function convertToPHPValue($value, AbstractPlatform $platform)
{
- return (null === $value) ? null : (double) $value;
+ return (null === $value) ? null : $value;
}
}
@@ -60,7 +60,7 @@ static public function dataIdempotentDataConversion()
array('array', array('foo' => 'bar'), 'array'),
array('object', $obj, 'object'),
array('float', 1.5, 'float'),
- array('decimal', 1.55, 'float'),
+ array('decimal', 1.55, 'string'),
);
}
@@ -21,7 +21,7 @@ protected function setUp()
public function testDecimalConvertsToPHPValue()
{
- $this->assertInternalType('float', $this->_type->convertToPHPValue('5.5', $this->_platform));
+ $this->assertInternalType('string', $this->_type->convertToPHPValue('5.5', $this->_platform));
}
public function testDecimalNullConvertsToPHPValue()

2 comments on commit 9f51afa

May I ask why ?

Member

stof replied Sep 4, 2013

@dlin-me because SQL decimals have an exact precision while floats don't. A typical use case for decimals is storing a price, where you don't want to loose this exact precision

Please sign in to comment.