From 49ab75afe8605ff2703a3094561ad4cc01ab2952 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Sat, 5 Sep 2020 00:19:32 +0200 Subject: [PATCH] Add new function MD_STD_IN::sanitize_float --- MD_STD_IN.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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; + + } + }