Esempio n. 1
0
bool BitcoinUnits::parse(int unit, const QString &value, qint64 *val_out, const QLocale &locale_in)
{
    if(!valid(unit) || value.isEmpty())
        return false; // Refuse to parse invalid unit or empty string

    QLocale locale(locale_in);
    qint64 coin = factor(unit);
    int num_decimals = decimals(unit);
    QStringList parts = value.split(locale.decimalPoint());
    bool ok = false;

    if(parts.size() > 2)
        return false; // More than one decimal point

    // Parse whole part (may include locale-specific group separators)
#if QT_VERSION < 0x050000
    qint64 whole = locale.toLongLong(parts[0], &ok, 10);
#else
    qint64 whole = locale.toLongLong(parts[0], &ok);
#endif
    if(!ok)
        return false; // Parse error
    if(whole > maxAmount(unit) || whole < 0)
        return false; // Overflow or underflow

    // Parse decimals part (if present, may not include group separators)
    qint64 decimals = 0;
    if(parts.size() > 1)
    {
        if(parts[1].size() > num_decimals)
            return false; // Exceeds max precision
        locale.setNumberOptions(QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator);
#if QT_VERSION < 0x050000
        decimals = locale.toLongLong(parts[1].leftJustified(num_decimals, '0'), &ok, 10);
#else
        decimals = locale.toLongLong(parts[1].leftJustified(num_decimals, '0'), &ok);
#endif
        if(!ok || decimals < 0)
            return false; // Parse error
    }

    if(val_out)
    {
        *val_out = whole * coin + decimals;
    }
    return ok;
}
Esempio n. 2
0
int main()
{
  int value; 
  int array[SIZE];
  int array2[SIZE]; //duplicate array
  int quantity;
  int funds;
  int maxCombination;
  int minCombination;
  int firstDesired;

//Function Call
value = Input(array); //value is number of item prices input
duplicate(value, array, array2); //creates a duplicate array to be used to check for min combination
quantity = Quantity(array, value); //gets number of items wanted
funds = Funds(array, value, quantity); //gets funds available
firstDesired = firstSum(array, quantity);
maxCombination = maxAmount(array, value, quantity); //finds max combination
minCombination = minAmount(array2, value, quantity);
result(funds, maxCombination, firstDesired, minCombination, quantity);
  return 0;
}
int LiquidContainerComponent::freeSpace() const
{
	return maxAmount() - amount_;
}