diff --git a/MD_STD_IN.php b/MD_STD_IN.php index f4b555d..ce56f6e 100644 --- a/MD_STD_IN.php +++ b/MD_STD_IN.php @@ -176,4 +176,21 @@ final class MD_STD_IN { } + /** + * Sanitizes a string to a float. + * + * @param string $input Input string. + * + * @return float + */ + final public static function sanitize_float(string $input):float { + + $output = \str_replace(",", ".", $input); + if (($output = \filter_var($output, FILTER_VALIDATE_FLOAT)) === false) { + throw new MDgenericInvalidInputsException("Input is readable as a floating point value"); + } + return $output; + + } + }