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))); } + }