summaryrefslogtreecommitdiffstats
path: root/src/lib/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util')
-rw-r--r--src/lib/util/str.cc7
-rw-r--r--src/lib/util/str.h7
2 files changed, 14 insertions, 0 deletions
diff --git a/src/lib/util/str.cc b/src/lib/util/str.cc
index 093cd0580b..0bb7e8f67f 100644
--- a/src/lib/util/str.cc
+++ b/src/lib/util/str.cc
@@ -340,6 +340,13 @@ dumpAsHex(const uint8_t* data, size_t length) {
return (output.str());
}
+string
+dumpDouble(double val, size_t precision) {
+ std::stringstream oss;
+ oss << setprecision(precision) << val;
+ return (oss.str());
+}
+
} // namespace str
} // namespace util
} // namespace isc
diff --git a/src/lib/util/str.h b/src/lib/util/str.h
index bd5587d717..c89294dc11 100644
--- a/src/lib/util/str.h
+++ b/src/lib/util/str.h
@@ -286,6 +286,13 @@ isPrintable(const std::vector<uint8_t>& content);
std::string
dumpAsHex(const uint8_t* data, size_t length);
+/// @brief Converts a double to a string with given precision
+///
+/// @param val double to convert
+/// @param precision number of maxium number decimal places to output
+/// @return string representaion of val
+std::string dumpDouble(double val, size_t precision = 5);
+
} // namespace str
} // namespace util
} // namespace isc