From dbfad62840090cafdefa3f5843e593403abfe1d3 Mon Sep 17 00:00:00 2001 From: psychon Date: Wed, 27 May 2009 11:24:26 +0000 Subject: [PATCH] CString now takes a precision for converting floating point numbers Because the precision defaults to 2, e.g. the traffic stats are now way more readable. Thanks to KiNgMaR for the idea and the patch. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1525 726aef4b-f618-498e-8847-2d620e286838 --- ZNCString.cpp | 4 ++-- ZNCString.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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) {}