|
4 | 4 |
|
5 | 5 | namespace MongoDB\Laravel\Eloquent; |
6 | 6 |
|
7 | | -use Brick\Math\BigDecimal; |
8 | | -use Brick\Math\Exception\MathException as BrickMathException; |
9 | | -use Brick\Math\RoundingMode; |
10 | 7 | use Carbon\CarbonInterface; |
11 | 8 | use DateTimeInterface; |
12 | 9 | use Illuminate\Contracts\Queue\QueueableCollection; |
|
15 | 12 | use Illuminate\Database\Eloquent\Model as BaseModel; |
16 | 13 | use Illuminate\Database\Eloquent\Relations\Relation; |
17 | 14 | use Illuminate\Support\Arr; |
18 | | -use Illuminate\Support\Exceptions\MathException; |
19 | 15 | use Illuminate\Support\Facades\Date; |
20 | 16 | use Illuminate\Support\Str; |
21 | 17 | use MongoDB\BSON\Binary; |
@@ -275,13 +271,12 @@ public function setAttribute($key, $value) |
275 | 271 | /** @inheritdoc */ |
276 | 272 | protected function asDecimal($value, $decimals) |
277 | 273 | { |
278 | | - try { |
279 | | - $value = (string) BigDecimal::of((string) $value)->toScale((int) $decimals, RoundingMode::HALF_UP); |
280 | | - |
281 | | - return new Decimal128($value); |
282 | | - } catch (BrickMathException $e) { |
283 | | - throw new MathException('Unable to cast value to a decimal.', previous: $e); |
| 274 | + if ($value instanceof Decimal128) { |
| 275 | + // Convert it to a string to round, want to make it act exactly like we expect. |
| 276 | + $value = (string) $value; |
284 | 277 | } |
| 278 | + |
| 279 | + return parent::asDecimal($value, $decimals); |
285 | 280 | } |
286 | 281 |
|
287 | 282 | /** @inheritdoc */ |
|
0 commit comments