Skip to content

Commit

Permalink
normalizeRow() don't return small float as string [Closes #289]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 10, 2022
1 parent fd7ccf2 commit b138afb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/Database/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ public static function normalizeRow(array $row, ResultSet $resultSet): array
$value = rtrim(rtrim($pos === 0 ? "0$value" : $value, '0'), '.');
}

$float = (float) $value;
$row[$key] = (string) $float === $value ? $float : $value;
$row[$key] = (float) $value;

} elseif ($type === IStructure::FIELD_BOOL) {
$row[$key] = ((bool) $value) && $value !== 'f' && $value !== 'F';
Expand Down
4 changes: 1 addition & 3 deletions tests/Database/ResultSet.normalizeRow.postgre.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/pgsql-nette_
$connection->query("SET TIMEZONE TO 'UTC'");

$res = $connection->query('SELECT * FROM types');

$row = $res->fetch();
Assert::type('string', $row->money);
unset($row->money);

Assert::equal([
'smallint' => 1,
Expand All @@ -30,6 +27,7 @@ Assert::equal([
'numeric' => 1.0,
'real' => 1.1,
'double' => 1.11,
'money' => 0.0,
'bool' => true,
'date' => new DateTime('2012-10-13'),
'time' => new DateTime('10:10:10'),
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/ResultSet.normalizeRow.sqlsrv.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Assert::equal([
'datetime' => new DateTime('2012-10-13 10:10:10'),
'datetime2' => new DateTime('2012-10-13 10:10:10'),
'decimal' => 1.0,
'float' => '1.1000000000000001',
'float' => 1.1,
'geography' => "\xe6\x10\x00\x00\x01\x14\x87\x16\xd9\xce\xf7\xd3G@\xd7\xa3p=\n\x97^\xc0\x87\x16\xd9\xce\xf7\xd3G@\xcb\xa1E\xb6\xf3\x95^\xc0",
'geometry' => "\x00\x00\x00\x00\x01\x04\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00Y@\x00\x00\x00\x00\x00\x00Y@\x00\x00\x00\x00\x00\x004@\x00\x00\x00\x00\x00\x80f@\x00\x00\x00\x00\x00\x80f@\x00\x00\x00\x00\x00\x80f@\x01\x00\x00\x00\x01\x00\x00\x00\x00\x01\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\x02",
'hierarchyid' => 'X',
Expand Down

0 comments on commit b138afb

Please sign in to comment.