mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Merge pull request #185 from jellehenkens/scientific-notation
Patch for ticket #1965 - Scientific notation in queries
This commit is contained in:
commit
37e32e9af5
2 changed files with 23 additions and 4 deletions
|
@ -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 &&
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue