Skip to content

Commit ad0c60f

Browse files
committed
Fixed BigDecimal::of error
1 parent 527c42c commit ad0c60f

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/Form/Type/BigDecimalMoneyType.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ public function reverseTransform($value): ?BigDecimal
5959
return null;
6060
}
6161

62-
return BigDecimal::of($value);
62+
if ($value instanceof BigDecimal) {
63+
return $value;
64+
}
65+
if (is_float($value)) {
66+
return BigDecimal::fromFloatShortest($value);
67+
}
68+
if (is_string($value)) {
69+
return BigDecimal::of($value);
70+
}
71+
72+
throw new \InvalidArgumentException(sprintf('Expected a string, float or BigDecimal, got %s', get_debug_type($value)));
6373
}
6474
}

src/Form/Type/BigDecimalNumberType.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ public function reverseTransform($value): ?BigDecimal
5959
return null;
6060
}
6161

62-
return BigDecimal::of($value);
62+
if ($value instanceof BigDecimal) {
63+
return $value;
64+
}
65+
if (is_float($value)) {
66+
return BigDecimal::fromFloatShortest($value);
67+
}
68+
if (is_string($value)) {
69+
return BigDecimal::of($value);
70+
}
71+
72+
throw new \InvalidArgumentException(sprintf('Expected a string, float or BigDecimal, got %s', get_debug_type($value)));
6373
}
74+
6475
}

0 commit comments

Comments
 (0)