Skip to content

Commit

Permalink
add null values support
Browse files Browse the repository at this point in the history
  • Loading branch information
514sid committed Sep 3, 2023
1 parent 903e9a1 commit df7f587
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Num.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@

class Num
{
public static function float(float|int|string $value, ?DecimalSeparator $decimalSeparator = null): float
public static function float(float|int|string|null $value, ?DecimalSeparator $decimalSeparator = null): float
{
if ($value === null) {
return 0.00;
}

return (float) NonNumericFilter::sanitize($value, $decimalSeparator);
}

public static function int(float|int|string $value, ?DecimalSeparator $decimalSeparator = null): int
public static function int(float|int|string|null $value, ?DecimalSeparator $decimalSeparator = null): int
{
if ($value === null) {
return 0;
}

return (int) NonNumericFilter::sanitize($value, $decimalSeparator);
}

Expand Down

0 comments on commit df7f587

Please sign in to comment.