diff --git a/server/core/config.c b/server/core/config.c index b55fa5a8a..27bb2af9a 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -2017,6 +2017,25 @@ config_truth_value(char *str) return atoi(str); } + +/** + * Converts a string into a floating point representation of a percentage value. + * For example 75% is converted to 0.75 and -10% is converted to -0.1. + * @param str String to convert + * @return String converted to a floating point percentage + */ +double +config_percentage_value(char *str) +{ + double value = 0; + + value = strtod(str,NULL); + if(value != 0) + value /= 100.0; + + return value; +} + static char *InternalRouters[] = { "debugcli", "cli", diff --git a/server/include/maxconfig.h b/server/include/maxconfig.h index 12b1b98fa..9912182c0 100644 --- a/server/include/maxconfig.h +++ b/server/include/maxconfig.h @@ -115,6 +115,7 @@ CONFIG_PARAMETER* config_get_param(CONFIG_PARAMETER* params, const char* name); config_param_type_t config_get_paramtype(CONFIG_PARAMETER* param); CONFIG_PARAMETER* config_clone_param(CONFIG_PARAMETER* param); extern int config_truth_value(char *); +extern double config_percentage_value(char *str); bool config_set_qualified_param( CONFIG_PARAMETER* param, void* val,