Merge #13264: [qt] Satoshi unit
c722f00a7
[qt] Added satoshi unit "Satoshi (sat)" will be displayed in dropdowns and status bars. "sat" will be used when appended to numbers. (GreatSock)4ddbcbf8c
[qt] BitcoinUnits::format with zero decimals Formatting with zero decimals will now result in 123 instead of 123.0 (GreatSock) Pull request description: This adds satoshi as an additional amount unit for the GUI. Tree-SHA512: c166c96c9a434b6ac700e1628e54f2dbb132c5232d949c0b464f61276a91d56f9bab4a62d50780535f1d34eaac6484f693a1e0611cd7c9d1ed5ebee066c0dd08
This commit is contained in:
commit
2a7c53bc2a
2 changed files with 20 additions and 7 deletions
|
@ -20,6 +20,7 @@ QList<BitcoinUnits::Unit> BitcoinUnits::availableUnits()
|
|||
unitlist.append(BTC);
|
||||
unitlist.append(mBTC);
|
||||
unitlist.append(uBTC);
|
||||
unitlist.append(SAT);
|
||||
return unitlist;
|
||||
}
|
||||
|
||||
|
@ -30,6 +31,7 @@ bool BitcoinUnits::valid(int unit)
|
|||
case BTC:
|
||||
case mBTC:
|
||||
case uBTC:
|
||||
case SAT:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
@ -43,6 +45,7 @@ QString BitcoinUnits::longName(int unit)
|
|||
case BTC: return QString("BTC");
|
||||
case mBTC: return QString("mBTC");
|
||||
case uBTC: return QString::fromUtf8("µBTC (bits)");
|
||||
case SAT: return QString("Satoshi (sat)");
|
||||
default: return QString("???");
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +55,8 @@ QString BitcoinUnits::shortName(int unit)
|
|||
switch(unit)
|
||||
{
|
||||
case uBTC: return QString::fromUtf8("bits");
|
||||
default: return longName(unit);
|
||||
case SAT: return QString("sat");
|
||||
default: return longName(unit);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,6 +67,7 @@ QString BitcoinUnits::description(int unit)
|
|||
case BTC: return QString("Bitcoins");
|
||||
case mBTC: return QString("Milli-Bitcoins (1 / 1" THIN_SP_UTF8 "000)");
|
||||
case uBTC: return QString("Micro-Bitcoins (bits) (1 / 1" THIN_SP_UTF8 "000" THIN_SP_UTF8 "000)");
|
||||
case SAT: return QString("Satoshi (sat) (1 / 100" THIN_SP_UTF8 "000" THIN_SP_UTF8 "000)");
|
||||
default: return QString("???");
|
||||
}
|
||||
}
|
||||
|
@ -71,10 +76,11 @@ qint64 BitcoinUnits::factor(int unit)
|
|||
{
|
||||
switch(unit)
|
||||
{
|
||||
case BTC: return 100000000;
|
||||
case BTC: return 100000000;
|
||||
case mBTC: return 100000;
|
||||
case uBTC: return 100;
|
||||
default: return 100000000;
|
||||
case SAT: return 1;
|
||||
default: return 100000000;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,6 +91,7 @@ int BitcoinUnits::decimals(int unit)
|
|||
case BTC: return 8;
|
||||
case mBTC: return 5;
|
||||
case uBTC: return 2;
|
||||
case SAT: return 0;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
@ -100,9 +107,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 +121,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -58,7 +58,8 @@ public:
|
|||
{
|
||||
BTC,
|
||||
mBTC,
|
||||
uBTC
|
||||
uBTC,
|
||||
SAT
|
||||
};
|
||||
|
||||
enum SeparatorStyle
|
||||
|
|
Loading…
Add table
Reference in a new issue