Add new function MD_STD_IN::sanitize_float

This commit is contained in:
Joshua Ramon Enslin 2020-09-05 00:19:32 +02:00 committed by Stefan Rohde-Enslin
parent 27b70a88c9
commit 49ab75afe8

View File

@ -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;
}
}