Skip to content

Commit 4cbad53

Browse files
committed
[Yaml] Use more concise float representation in dump
1 parent 9cb8298 commit 4cbad53

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Inline.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ public static function dump($value, int $flags = 0): string
174174
$repr = str_ireplace('INF', '.Inf', $repr);
175175
} elseif (floor($value) == $value && $repr == $value) {
176176
// Preserve float data type since storing a whole number will result in integer value.
177-
$repr = '!!float '.$repr;
177+
if (false === strpos($repr, 'E')) {
178+
$repr = $repr.'.';
179+
}
178180
}
179181
} else {
180182
$repr = \is_string($value) ? "'$value'" : (string) $value;

Tests/InlineTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ public function getTestsForParse()
298298
['12_', 12],
299299
['"quoted string"', 'quoted string'],
300300
["'quoted string'", 'quoted string'],
301+
['1234.', 1234.],
301302
['12.30e+02', 12.30e+02],
302303
['123.45_67', 123.4567],
303304
['0x4D2', 0x4D2],
@@ -461,7 +462,8 @@ public function getTestsForDump()
461462
['_12', '_12'],
462463
["'12_'", '12_'],
463464
["'quoted string'", 'quoted string'],
464-
['!!float 1230', 12.30e+02],
465+
['1230.', 12.30e+02],
466+
['1.23E+45', 12.30e+44],
465467
['1234', 0x4D2],
466468
['1243', 02333],
467469
["'0x_4_D_2_'", '0x_4_D_2_'],

0 commit comments

Comments
 (0)