From ee5f1dd293354f4db3a597f0e85073a0a352c7b9 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 13 Oct 2015 13:14:08 +0200 Subject: [PATCH] Result: fixed normalization of float when ends with "0" [Closes #189] --- dibi/libs/DibiResult.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dibi/libs/DibiResult.php b/dibi/libs/DibiResult.php index ac3f9e0a..ead57984 100644 --- a/dibi/libs/DibiResult.php +++ b/dibi/libs/DibiResult.php @@ -495,7 +495,17 @@ class DibiResult extends DibiObject implements IDataSource $row[$key] = is_float($tmp = $value * 1) ? $value : $tmp; } elseif ($type === dibi::FLOAT) { - $row[$key] = str_replace(',', '.', ltrim((string) ($tmp = (float) $value), '0')) === ltrim(rtrim(rtrim($value, '0'), '.'), '0') ? $tmp : $value; + $value = ltrim($value, '0'); + $p = strpos($value, '.'); + if ($p !== FALSE) { + $value = rtrim(rtrim($value, '0'), '.'); + } + if ($value === '' || $value[0] === '.') { + $value = '0' . $value; + } + $row[$key] = $value === str_replace(',', '.', (string) ($float = (float) $value)) + ? $float + : $value; } elseif ($type === dibi::BOOL) { $row[$key] = ((bool) $value) && $value !== 'f' && $value !== 'F';