From: Guilherme Maciel Ferreira Date: Thu, 3 Feb 2011 09:01:43 +0000 (+0100) Subject: Moved the rounding statement to its own function X-Git-Tag: v2.6~86^2~7 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=72a944266237f56a3dbed7ba5e499b346ee1c373;p=libi2ncommon Moved the rounding statement to its own function --- diff --git a/src/stringfunc.cpp b/src/stringfunc.cpp index 310cb01..23b120d 100644 --- a/src/stringfunc.cpp +++ b/src/stringfunc.cpp @@ -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;