Add new function MD_STD_IN::sanitize_float
This commit is contained in:
parent
27b70a88c9
commit
49ab75afe8
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user