From df7f587dfe9d0c9954cdb648c8da7ab65c4831db Mon Sep 17 00:00:00 2001 From: 514sid <140138716+514sid@users.noreply.github.com> Date: Sun, 3 Sep 2023 10:19:23 +0400 Subject: [PATCH] add null values support --- src/Num.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Num.php b/src/Num.php index 6b49a06..bf6be36 100644 --- a/src/Num.php +++ b/src/Num.php @@ -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); }