{
switch(unit)
{
- case BTC: return QString("BTC");
- case mBTC: return QString("mBTC");
- case uBTC: return QString::fromUtf8("μBTC");
+ case BTC: return QString("NVC");
+ case mBTC: return QString("mNVC");
+ case uBTC: return QString::fromUtf8("μNVC");
default: return QString("???");
}
}
{
switch(unit)
{
- case BTC: return QString("Bitcoins");
- case mBTC: return QString("Milli-Bitcoins (1 / 1,000)");
- case uBTC: return QString("Micro-Bitcoins (1 / 1,000,000)");
+ case BTC: return QString(QObject::tr("NovaCoins"));
+ case mBTC: return QString(QObject::tr("Milli-NovaCoins (1 / 1,000)"));
+ case uBTC: return QString(QObject::tr("Micro-NovaCoins (1 / 1,000,000)"));
default: return QString("???");
}
}
{
switch(unit)
{
- case BTC: return 100000000;
- case mBTC: return 100000;
- case uBTC: return 100;
- default: return 100000000;
+ case BTC: return 1000000;
+ case mBTC: return 1000;
+ case uBTC: return 1;
+ default: return 1000000;
}
}
{
switch(unit)
{
- case BTC: return 8;
- case mBTC: return 5;
- case uBTC: return 2;
+ case BTC: return 6;
+ case mBTC: return 3;
+ case uBTC: return 0;
default: return 0;
}
}
-QString BitcoinUnits::format(int unit, qint64 n, bool fPlus)
+QString BitcoinUnits::format(int unit, qint64 n, bool fPlus, uint8_t nNumberOfZeros)
{
// Note: not using straight sprintf here because we do NOT want
// localized number formatting.
QString quotient_str = QString::number(quotient);
QString remainder_str = QString::number(remainder).rightJustified(num_decimals, '0');
- // Right-trim excess 0's after the decimal point
+ // Right-trim excess zeros after the decimal point
int nTrim = 0;
- for (int i = remainder_str.size()-1; i>=2 && (remainder_str.at(i) == '0'); --i)
+ for (int i = remainder_str.size()-1; i>=nNumberOfZeros && (remainder_str.at(i) == '0'); --i)
++nTrim;
remainder_str.chop(nTrim);
return quotient_str + QString(".") + remainder_str;
}
-QString BitcoinUnits::formatWithUnit(int unit, qint64 amount, bool plussign)
+QString BitcoinUnits::formatWithUnit(int unit, qint64 amount, bool plussign, uint8_t nNumberOfZeros)
{
- return format(unit, amount, plussign) + QString(" ") + name(unit);
+ return format(unit, amount, plussign, nNumberOfZeros) + QString(" ") + name(unit);
}
bool BitcoinUnits::parse(int unit, const QString &value, qint64 *val_out)
{
- if(!valid(unit))
- return false; // Refuse to parse invalid unit
+ if(!valid(unit) || value.isEmpty())
+ return false; // Refuse to parse invalid unit or empty string
int num_decimals = decimals(unit);
QStringList parts = value.split(".");
- if(parts.size() != 2 || parts.at(1).size() > num_decimals)
- return false; // Max num decimals
+
+ if(parts.size() > 2)
+ {
+ return false; // More than one dot
+ }
+ QString whole = parts[0];
+ QString decimals;
+
+ if(parts.size() > 1)
+ {
+ decimals = parts[1];
+ }
+ if(decimals.size() > num_decimals)
+ {
+ return false; // Exceeds max precision
+ }
bool ok = false;
- QString str = parts[0] + parts[1].leftJustified(num_decimals, '0');
- if(str.size()>18)
- return false; // Bounds check
+ QString str = whole + decimals.leftJustified(num_decimals, '0');
+ if(str.size() > 18)
+ {
+ return false; // Longer numbers will exceed 63 bits
+ }
qint64 retvalue = str.toLongLong(&ok);
if(val_out)
{
}
return QVariant();
}
+
+QString BitcoinUnits::getAmountColumnTitle(int unit)
+{
+ QString amountTitle = QObject::tr("Amount");
+ if (BitcoinUnits::valid(unit))
+ {
+ amountTitle += " ("+BitcoinUnits::name(unit) + ")";
+ }
+ return amountTitle;
+}
\ No newline at end of file