21 double multiplier = 1000.0;
22 static const char* SI_endings[] = {
23 "",
"k",
"M",
"G",
"T",
"P",
"E" 25 unsigned int scale = 0;
26 double number_d =
static_cast<double>(number);
27 while (number_d >= multiplier) {
28 number_d /= multiplier;
31 std::ostringstream out;
32 out << std::fixed << std::setprecision(precision) << number_d
33 <<
' ' << SI_endings[scale];
40 double multiplier = 1024.0;
41 static const char* IEC_endings[] = {
42 "",
"Ki",
"Mi",
"Gi",
"Ti",
"Pi",
"Ei" 44 unsigned int scale = 0;
45 double number_d =
static_cast<double>(number);
46 while (number_d >= multiplier) {
47 number_d /= multiplier;
50 std::ostringstream out;
51 out << std::fixed << std::setprecision(precision) << number_d
52 <<
' ' << IEC_endings[scale];
std::string format_si_units(uint64_t number, int precision)
Format number as something like 1 TB.
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
std::string format_iec_units(uint64_t number, int precision=3)
Format number as something like 1 TiB.