Skip to content

Commit f377436

Browse files
authored
Update Decimal2.php
1 parent a5dd1a4 commit f377436

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Diff for: src/Cast/Decimal2.php

+13-9
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
66
use Illuminate\Database\Eloquent\Model;
77

8+
/**
9+
* @implements CastsAttributes<Decimal, Decimal>
10+
*/
811
class Decimal2 implements CastsAttributes
912
{
1013
/**
1114
* Cast the given value.
1215
*
1316
* @param Model $model
14-
* @param string $key
15-
* @param numeric-string|int $value
16-
* @param array $attributes
17+
* @param numeric-string $value
18+
* @param array<mixed> $attributes
1719
*/
1820
public function get($model, string $key, $value, array $attributes): Decimal
1921
{
@@ -24,14 +26,16 @@ public function get($model, string $key, $value, array $attributes): Decimal
2426
* Prepare the given value for storage.
2527
*
2628
* @param Model $model
27-
* @param string $key
28-
* @param Decimal $value
29-
* @param array $attributes
29+
* @param array<mixed> $attributes
3030
*
31-
* @return numeric-string
31+
* @return ?string
3232
*/
33-
public function set($model, string $key, $value, array $attributes): string
33+
public function set($model, string $key, $value, array $attributes): ?string
3434
{
35-
return $value->toFixed($decimals, $commas = false, PHP_ROUND_HALF_UP);
35+
if ($value === null) {
36+
return null;
37+
}
38+
39+
return $value->toFixed($value->precision(), false, PHP_ROUND_HALF_UP);
3640
}
3741
}

0 commit comments

Comments
 (0)