Moved the rounding statement to its own function
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Thu, 3 Feb 2011 09:01:43 +0000 (10:01 +0100)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Thu, 3 Feb 2011 09:01:43 +0000 (10:01 +0100)
src/stringfunc.cpp

index 310cb01..23b120d 100644 (file)
@@ -892,7 +892,6 @@ string to_upper(const string &src)
 }
 #endif
 
-
 const int MAX_SYMBOL_FORMATS = 9;
 
 const string symbolFormatShort[MAX_SYMBOL_FORMATS] = {
@@ -919,6 +918,22 @@ const string symbolFormatLong[MAX_SYMBOL_FORMATS] = {
         " YBytes"
 };
 
+
+long double rounding_upwards(
+        long double number,
+        const int rounding_multiplier
+)
+{
+    long double rounded_number;
+    rounded_number = number * rounding_multiplier;
+    rounded_number += 0.5;
+    rounded_number = (int64_t) (rounded_number);
+    rounded_number = (long double) (rounded_number) / (long double) (rounding_multiplier);
+
+    return rounded_number;
+}
+
+
 string nice_unit_format(
         const int64_t input,
         const UnitBase base,
@@ -948,12 +963,7 @@ string nice_unit_format(
 
    // round the input number "half up" to multiples of 10
    const int rounding_multiplier = 10;
-   long double tmp;
-   tmp = size * rounding_multiplier;
-   tmp += 0.5;
-   tmp = (int64_t) (tmp);
-   tmp = (long double) (tmp) / (long double) (rounding_multiplier);
-   size = tmp;
+   size = rounding_upwards(size, rounding_multiplier);
 
    // format the input number, placing the appropriate symbol
    ostringstream out;