Merge pull request #185 from jellehenkens/scientific-notation

Patch for ticket #1965 - Scientific notation in queries
This commit is contained in:
Mark Story 2011-09-05 01:55:37 -07:00
commit 37e32e9af5
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
*