1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-10 16:14:57 +02:00

Result: fixed normalization of float when ends with "0" [Closes #189]

This commit is contained in:
David Grudl
2015-10-13 13:14:08 +02:00
parent 5b9ffe14ba
commit 4ae4f49c21
2 changed files with 83 additions and 1 deletions

View File

@@ -494,7 +494,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';