Skip to content

Commit

Permalink
Result::normalize() Fix select float in format of e-notation (#317) v…
Browse files Browse the repository at this point in the history
…3.2 (#320)
  • Loading branch information
chrudosvorlicek authored and dg committed Oct 25, 2018
1 parent 69ea60c commit 6aa8a43
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Dibi/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,11 @@ private function normalize(array &$row)
} elseif ($type === Type::FLOAT) {
$value = ltrim((string) $value, '0');
$p = strpos($value, '.');
if ($p !== false) {
$e = strpos($value, 'e');
if ($p !== false && $e === false) {
$value = rtrim(rtrim($value, '0'), '.');
} elseif ($p !== false && $e !== false) {
$value = rtrim($value, '.');
}
if ($value === '' || $value[0] === '.') {
$value = '0' . $value;
Expand Down
5 changes: 5 additions & 0 deletions tests/dibi/Result.normalize.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ test(function () {
Assert::same(['col' => 1.0], $result->test(['col' => 1]));
Assert::same(['col' => 1.0], $result->test(['col' => 1.0]));

Assert::same(['col' => '1.1e+10'], $result->test(['col' => '1.1e+10']));
Assert::same(['col' => '1.1e-10'], $result->test(['col' => '1.1e-10']));
Assert::same(['col' => '1.1e+10'], $result->test(['col' => '001.1e+10']));
Assert::notSame(['col' => '1.1e+1'], $result->test(['col' => '1.1e+10']));

setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');
Assert::same(['col' => 0.0], $result->test(['col' => '']));
Assert::same(['col' => 0.0], $result->test(['col' => '0']));
Expand Down

0 comments on commit 6aa8a43

Please sign in to comment.