Fixing bug where scientific notations were not passed to mysql in their original form which resulted in loss of precision

This commit is contained in:
Jelle Henkens 2011-09-05 01:21:38 +01:00
parent 15a1741216
commit 53d221c3d1
2 changed files with 23 additions and 4 deletions

View file

@ -672,7 +672,7 @@ class DboMysql extends DboMysqlBase {
return 'NULL';
}
if (is_float($data)) {
return sprintf('%F', $data);
return str_replace(',', '.', sprintf('%G', $data));
}
if ((is_int($data) || $data === '0') || (
is_numeric($data) && strpos($data, ',') === false &&

View file

@ -239,14 +239,33 @@ class DboMysqlTest extends CakeTestCase {
setlocale(LC_ALL, 'de_DE');
$result = $this->db->value(3.141593, 'float');
$this->assertEqual((string)$result, '3.141593');
$this->assertTrue(strpos((string)$result, ',') === false);
$result = $this->db->value(3.141593);
$this->assertEqual((string)$result, '3.141593');
$this->assertTrue(strpos((string)$result, ',') === false);
$result = $this->db->value(2.2E-54, 'float');
$this->assertEqual('2.2E-54', (string)$result);
$result = $this->db->value(2.2E-54);
$this->assertEqual('2.2E-54', (string)$result);
setlocale(LC_ALL, $restore);
}
/**
* test that scientific notations are working correctly
*
* @return void
*/
function testScientificNotation() {
$result = $this->db->value(2.2E-54, 'float');
$this->assertEqual('2.2E-54', (string)$result);
$result = $this->db->value(2.2E-54);
$this->assertEqual('2.2E-54', (string)$result);
}
/**
* testTinyintCasting method
*