summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/rfb/util.cxx14
-rw-r--r--common/rfb/util.h4
2 files changed, 10 insertions, 8 deletions
diff --git a/common/rfb/util.cxx b/common/rfb/util.cxx
index aec45f61..22e00ffc 100644
--- a/common/rfb/util.cxx
+++ b/common/rfb/util.cxx
@@ -139,7 +139,7 @@ namespace rfb {
static size_t doPrefix(long long value, const char *unit,
char *buffer, size_t maxlen,
unsigned divisor, const char **prefixes,
- size_t prefixCount) {
+ size_t prefixCount, int precision) {
double newValue;
size_t prefix, len;
@@ -152,7 +152,7 @@ namespace rfb {
prefix++;
}
- len = snprintf(buffer, maxlen, "%g %s%s", newValue,
+ len = snprintf(buffer, maxlen, "%.*g %s%s", precision, newValue,
(prefix == 0) ? "" : prefixes[prefix-1], unit);
buffer[maxlen-1] = '\0';
@@ -165,14 +165,16 @@ namespace rfb {
{ "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" };
size_t siPrefix(long long value, const char *unit,
- char *buffer, size_t maxlen) {
+ char *buffer, size_t maxlen, int precision) {
return doPrefix(value, unit, buffer, maxlen, 1000, siPrefixes,
- sizeof(siPrefixes)/sizeof(*siPrefixes));
+ sizeof(siPrefixes)/sizeof(*siPrefixes),
+ precision);
}
size_t iecPrefix(long long value, const char *unit,
- char *buffer, size_t maxlen) {
+ char *buffer, size_t maxlen, int precision) {
return doPrefix(value, unit, buffer, maxlen, 1024, iecPrefixes,
- sizeof(iecPrefixes)/sizeof(*iecPrefixes));
+ sizeof(iecPrefixes)/sizeof(*iecPrefixes),
+ precision);
}
};
diff --git a/common/rfb/util.h b/common/rfb/util.h
index 9ad17720..e9114c3d 100644
--- a/common/rfb/util.h
+++ b/common/rfb/util.h
@@ -99,9 +99,9 @@ namespace rfb {
unsigned msSince(const struct timeval *then);
size_t siPrefix(long long value, const char *unit,
- char *buffer, size_t maxlen);
+ char *buffer, size_t maxlen, int precision=6);
size_t iecPrefix(long long value, const char *unit,
- char *buffer, size_t maxlen);
+ char *buffer, size_t maxlen, int precision=6);
}
// Some platforms (e.g. Windows) include max() and min() macros in their