From 0aad5a13009d474bd29d2ddc76b895ae826fcf61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 28 Jul 2024 21:52:06 +0200 Subject: [PATCH] Fix parsing of numbers in exponential notation and negative exponent A value like 1E-3 results in a float value, even if it not contains the decimal separator. NumberFormatter can parse this correctly, but we need to pass TYPE_DOUBLE. Before it were only used when the string contained the decimal separator, therefore the TYPE_INT was used before (which resulted in the inproper result of 0). --- .../DataTransformer/NumberToLocalizedStringTransformer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php index 2a6d146f90824..1457ab872b2b5 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php @@ -104,7 +104,8 @@ public function reverseTransform(mixed $value): int|float|null $value = str_replace(',', $decSep, $value); } - if (str_contains($value, $decSep)) { + //If the value is in exponential notation with a negative exponent, we end up with a float value too + if (str_contains($value, $decSep) || stripos($value, 'e-') !== false) { $type = \NumberFormatter::TYPE_DOUBLE; } else { $type = \PHP_INT_SIZE === 8