MINOR: tools: add new round_2dig() function to round integers

This function rounds down an integer to the closest value having only
2 significant digits.
This commit is contained in:
Willy Tarreau 2015-01-15 18:43:49 +01:00
parent 8c97ab5eb2
commit 3ca1a883f9
2 changed files with 14 additions and 0 deletions

View File

@ -242,6 +242,8 @@ static inline int hex2i(int c)
return c;
}
/* rounds <i> down to the closest value having max 2 digits */
unsigned int round_2dig(unsigned int i);
/*
* Checks <name> for invalid characters. Valid chars are [A-Za-z0-9_:.-]. If an

View File

@ -504,6 +504,18 @@ int ishex(char s)
return 0;
}
/* rounds <i> 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 <name> 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