diff --git a/ZNCString.cpp b/ZNCString.cpp index fbc0bf43..0d1ea967 100644 --- a/ZNCString.cpp +++ b/ZNCString.cpp @@ -139,8 +139,8 @@ CString::CString(long i) : string() { stringstream s; s << i; *this = s.str(); } CString::CString(unsigned long i) : string() { stringstream s; s << i; *this = s.str(); } CString::CString(long long i) : string() { stringstream s; s << i; *this = s.str(); } CString::CString(unsigned long long i) : string() { stringstream s; s << i; *this = s.str(); } -CString::CString(double i) : string() { stringstream s; s << i; *this = s.str(); } -CString::CString(float i) : string() { stringstream s; s << i; *this = s.str(); } +CString::CString(double i, int precision) : string() { stringstream s; s.precision(precision); s << std::fixed << i; *this = s.str(); } +CString::CString(float i, int precision) : string() { stringstream s; s.precision(precision); s << std::fixed << i; *this = s.str(); } inline unsigned char* CString::strnchr(const unsigned char* src, unsigned char c, unsigned int iMaxBytes, unsigned char* pFill, unsigned int* piCount) const { for (unsigned int a = 0; a < iMaxBytes && *src; a++, src++) { diff --git a/ZNCString.h b/ZNCString.h index 85b20108..4a9df7e9 100644 --- a/ZNCString.h +++ b/ZNCString.h @@ -70,8 +70,8 @@ public: explicit CString(unsigned long i); explicit CString(long long i); explicit CString(unsigned long long i); - explicit CString(double i); - explicit CString(float i); + explicit CString(double i, int precision = 2); + explicit CString(float i, int precision = 2); CString() : string() {} CString(const char* c) : string(c) {}