mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-22 10:02:34 +02:00
[qt] BitcoinUnits::format with zero decimals
Formatting with zero decimals will now result in 123 instead of 123.0
This commit is contained in:
parent
4cfe17c338
commit
4ddbcbf8c4
@ -100,9 +100,7 @@ QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, Separator
|
|||||||
int num_decimals = decimals(unit);
|
int num_decimals = decimals(unit);
|
||||||
qint64 n_abs = (n > 0 ? n : -n);
|
qint64 n_abs = (n > 0 ? n : -n);
|
||||||
qint64 quotient = n_abs / coin;
|
qint64 quotient = n_abs / coin;
|
||||||
qint64 remainder = n_abs % coin;
|
|
||||||
QString quotient_str = QString::number(quotient);
|
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
|
// Use SI-style thin space separators as these are locale independent and can't be
|
||||||
// confused with the decimal marker.
|
// confused with the decimal marker.
|
||||||
@ -116,7 +114,14 @@ QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, Separator
|
|||||||
quotient_str.insert(0, '-');
|
quotient_str.insert(0, '-');
|
||||||
else if (fPlus && n > 0)
|
else if (fPlus && n > 0)
|
||||||
quotient_str.insert(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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user