aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2011-02-23 16:01:17 -0500
committerGavin Andresen <gavinandresen@gmail.com>2011-02-23 16:01:17 -0500
commit87504abb070cf9df4b2bf24787ce14643df9b07d (patch)
treeb067e199ced98c44259eaf8b01f9112e8057f917
parent789259d2e72f28330dbe70e8acfdf752bd950b76 (diff)
FormatMoney: show full-precision values
-rw-r--r--util.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/util.cpp b/util.cpp
index 94b0242dc7..5f6f10a329 100644
--- a/util.cpp
+++ b/util.cpp
@@ -313,9 +313,18 @@ void ParseString(const string& str, char c, vector<string>& v)
string FormatMoney(int64 n, bool fPlus)
{
- n /= CENT;
- string str = strprintf("%"PRI64d".%02"PRI64d, (n > 0 ? n : -n)/100, (n > 0 ? n : -n)%100);
- for (int i = 6; i < str.size(); i += 4)
+ string str = strprintf("%.08f", double(n > 0 ? n : -n)/double(COIN));
+
+ // Right-trim excess 0's before the decimal point:
+ int nTrim = 0;
+ for (int i = str.size()-1; (str[i] == '0' && isdigit(str[i-2])); --i)
+ ++nTrim;
+ if (nTrim)
+ str.erase(str.size()-nTrim, nTrim);
+
+ // Insert thousands-separators:
+ size_t point = str.find(".");
+ for (int i = (str.size()-point)+3; i < str.size(); i += 4)
if (isdigit(str[str.size() - i - 1]))
str.insert(str.size() - i, 1, ',');
if (n < 0)