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.
diff --git a/src/standard.c b/src/standard.c
index 00e672a..93c44bb 100644
--- a/src/standard.c
+++ b/src/standard.c
@@ -504,6 +504,18 @@
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