From ad0c60f76653d2aac160a7892aba7bcfd538bf5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Tue, 19 May 2026 22:02:15 +0200 Subject: [PATCH] Fixed BigDecimal::of error --- src/Form/Type/BigDecimalMoneyType.php | 12 +++++++++++- src/Form/Type/BigDecimalNumberType.php | 13 ++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Form/Type/BigDecimalMoneyType.php b/src/Form/Type/BigDecimalMoneyType.php index 189416ff..1950391c 100644 --- a/src/Form/Type/BigDecimalMoneyType.php +++ b/src/Form/Type/BigDecimalMoneyType.php @@ -59,6 +59,16 @@ class BigDecimalMoneyType extends AbstractType implements DataTransformerInterfa return null; } - return BigDecimal::of($value); + if ($value instanceof BigDecimal) { + return $value; + } + if (is_float($value)) { + return BigDecimal::fromFloatShortest($value); + } + if (is_string($value)) { + return BigDecimal::of($value); + } + + throw new \InvalidArgumentException(sprintf('Expected a string, float or BigDecimal, got %s', get_debug_type($value))); } } diff --git a/src/Form/Type/BigDecimalNumberType.php b/src/Form/Type/BigDecimalNumberType.php index c225f0a4..04e8e655 100644 --- a/src/Form/Type/BigDecimalNumberType.php +++ b/src/Form/Type/BigDecimalNumberType.php @@ -59,6 +59,17 @@ class BigDecimalNumberType extends AbstractType implements DataTransformerInterf return null; } - return BigDecimal::of($value); + if ($value instanceof BigDecimal) { + return $value; + } + if (is_float($value)) { + return BigDecimal::fromFloatShortest($value); + } + if (is_string($value)) { + return BigDecimal::of($value); + } + + throw new \InvalidArgumentException(sprintf('Expected a string, float or BigDecimal, got %s', get_debug_type($value))); } + }