Added percentage conversion functions to maxconfig.h

This commit is contained in:
Markus Makela 2015-04-16 21:51:19 +03:00
parent 1b3af7d61f
commit 4b623e3af4
2 changed files with 20 additions and 0 deletions

View File

@ -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",

View File

@ -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,