mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-07 11:12:50 +01:00
Use a typedef for monetary values
This commit is contained in:
committed by
Mark Friedenbach
parent
64cfaf891f
commit
a372168e77
@@ -91,12 +91,13 @@ int BitcoinUnits::decimals(int unit)
|
||||
}
|
||||
}
|
||||
|
||||
QString BitcoinUnits::format(int unit, qint64 n, bool fPlus, SeparatorStyle separators)
|
||||
QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, SeparatorStyle separators)
|
||||
{
|
||||
// Note: not using straight sprintf here because we do NOT want
|
||||
// localized number formatting.
|
||||
if(!valid(unit))
|
||||
return QString(); // Refuse to format invalid unit
|
||||
qint64 n = (qint64)nIn;
|
||||
qint64 coin = factor(unit);
|
||||
int num_decimals = decimals(unit);
|
||||
qint64 n_abs = (n > 0 ? n : -n);
|
||||
@@ -138,12 +139,12 @@ QString BitcoinUnits::format(int unit, qint64 n, bool fPlus, SeparatorStyle sepa
|
||||
// Please take care to use formatHtmlWithUnit instead, when
|
||||
// appropriate.
|
||||
|
||||
QString BitcoinUnits::formatWithUnit(int unit, qint64 amount, bool plussign, SeparatorStyle separators)
|
||||
QString BitcoinUnits::formatWithUnit(int unit, const CAmount& amount, bool plussign, SeparatorStyle separators)
|
||||
{
|
||||
return format(unit, amount, plussign, separators) + QString(" ") + name(unit);
|
||||
}
|
||||
|
||||
QString BitcoinUnits::formatHtmlWithUnit(int unit, qint64 amount, bool plussign, SeparatorStyle separators)
|
||||
QString BitcoinUnits::formatHtmlWithUnit(int unit, const CAmount& amount, bool plussign, SeparatorStyle separators)
|
||||
{
|
||||
QString str(formatWithUnit(unit, amount, plussign, separators));
|
||||
str.replace(QChar(THIN_SP_CP), QString(THIN_SP_HTML));
|
||||
@@ -151,7 +152,7 @@ QString BitcoinUnits::formatHtmlWithUnit(int unit, qint64 amount, bool plussign,
|
||||
}
|
||||
|
||||
|
||||
bool BitcoinUnits::parse(int unit, const QString &value, qint64 *val_out)
|
||||
bool BitcoinUnits::parse(int unit, const QString &value, CAmount *val_out)
|
||||
{
|
||||
if(!valid(unit) || value.isEmpty())
|
||||
return false; // Refuse to parse invalid unit or empty string
|
||||
@@ -182,7 +183,7 @@ bool BitcoinUnits::parse(int unit, const QString &value, qint64 *val_out)
|
||||
{
|
||||
return false; // Longer numbers will exceed 63 bits
|
||||
}
|
||||
qint64 retvalue = str.toLongLong(&ok);
|
||||
CAmount retvalue(str.toLongLong(&ok));
|
||||
if(val_out)
|
||||
{
|
||||
*val_out = retvalue;
|
||||
@@ -226,7 +227,7 @@ QVariant BitcoinUnits::data(const QModelIndex &index, int role) const
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
qint64 BitcoinUnits::maxMoney()
|
||||
CAmount BitcoinUnits::maxMoney()
|
||||
{
|
||||
return MAX_MONEY;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user