diff --git a/lib/PhpParser/PrettyPrinter/Standard.php b/lib/PhpParser/PrettyPrinter/Standard.php index 477b490..9d4ea2e 100644 --- a/lib/PhpParser/PrettyPrinter/Standard.php +++ b/lib/PhpParser/PrettyPrinter/Standard.php @@ -97,6 +97,9 @@ class Standard extends PrettyPrinterAbstract public function pScalar_DNumber(Scalar\DNumber $node) { $stringValue = sprintf('%.16G', $node->value); + if ($node->value !== (double) $stringValue) { + $stringValue = sprintf('%.17G', $node->value); + } // ensure that number is really printed as float return preg_match('/^-?[0-9]+$/', $stringValue) ? $stringValue . '.0' : $stringValue; diff --git a/test/code/prettyPrinter/literals.test b/test/code/prettyPrinter/literals.test index 5da1268..7ba53db 100644 --- a/test/code/prettyPrinter/literals.test +++ b/test/code/prettyPrinter/literals.test @@ -38,6 +38,7 @@ FALSE; 1E-100; 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000; 378282246310005.0; +10000000000000002.0; // strings (normalized to single quoted) 'a'; @@ -114,6 +115,7 @@ INF; 1.0E-100; 1.0E+84; 378282246310005.0; +10000000000000002.0; // strings (normalized to single quoted) 'a'; 'a