aboutsummaryrefslogtreecommitdiff
path: root/src/qt/bitcoinunits.cpp
diff options
context:
space:
mode:
authorGreatSock <greatsock@protonmail.com>2018-05-17 15:50:09 +0200
committerGreatSock <greatsock@protonmail.com>2018-05-17 15:50:09 +0200
commit4ddbcbf8c4bd0567d2fa83da32db4fbbc7c675fc (patch)
treeecd3b3b57d435003e2c5dd5bd3106813981be7ca /src/qt/bitcoinunits.cpp
parent4cfe17c3382ba750131cdc8703b2978132822070 (diff)
[qt] BitcoinUnits::format with zero decimals
Formatting with zero decimals will now result in 123 instead of 123.0
Diffstat (limited to 'src/qt/bitcoinunits.cpp')
-rw-r--r--src/qt/bitcoinunits.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/qt/bitcoinunits.cpp b/src/qt/bitcoinunits.cpp
index 9df05d2a13..1f9792a112 100644
--- a/src/qt/bitcoinunits.cpp
+++ b/src/qt/bitcoinunits.cpp
@@ -100,9 +100,7 @@ QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, Separator
int num_decimals = decimals(unit);
qint64 n_abs = (n > 0 ? n : -n);
qint64 quotient = n_abs / coin;
- qint64 remainder = n_abs % coin;
QString quotient_str = QString::number(quotient);
- QString remainder_str = QString::number(remainder).rightJustified(num_decimals, '0');
// Use SI-style thin space separators as these are locale independent and can't be
// confused with the decimal marker.
@@ -116,7 +114,14 @@ QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, Separator
quotient_str.insert(0, '-');
else if (fPlus && n > 0)
quotient_str.insert(0, '+');
- return quotient_str + QString(".") + remainder_str;
+
+ if (num_decimals > 0) {
+ qint64 remainder = n_abs % coin;
+ QString remainder_str = QString::number(remainder).rightJustified(num_decimals, '0');
+ return quotient_str + QString(".") + remainder_str;
+ } else {
+ return quotient_str;
+ }
}