mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
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:
parent
15a1741216
commit
53d221c3d1
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…
Add table
Reference in a new issue