diff --git a/include/common/standard.h b/include/common/standard.h index e9900d54a..427d0d725 100644 --- a/include/common/standard.h +++ b/include/common/standard.h @@ -242,6 +242,8 @@ static inline int hex2i(int c) return c; } +/* rounds down to the closest value having max 2 digits */ +unsigned int round_2dig(unsigned int i); /* * Checks for invalid characters. Valid chars are [A-Za-z0-9_:.-]. If an diff --git a/src/standard.c b/src/standard.c index 00e672add..93c44bb3c 100644 --- a/src/standard.c +++ b/src/standard.c @@ -504,6 +504,18 @@ int ishex(char s) return 0; } +/* rounds down to the closest value having max 2 digits */ +unsigned int round_2dig(unsigned int i) +{ + unsigned int mul = 1; + + while (i >= 100) { + i /= 10; + mul *= 10; + } + return i * mul; +} + /* * Checks for invalid characters. Valid chars are [A-Za-z0-9_:.-]. If an * invalid character is found, a pointer to it is returned. If everything is