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 int num_decimals = decimals(unit); // Ignore spaces and thin spaces when parsing QStringList parts = removeSpaces(value).split("."); 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 = whole + decimals.leftJustified(num_decimals, '0'); if (str.size() > 18) { return false; // Longer numbers will exceed 63 bits } CAmount retvalue(str.toLongLong(&ok)); if (val_out) { *val_out = retvalue; } return ok; }
bool moorecoinunits::parse(int unit, const qstring &value, camount *val_out) { if(!valid(unit) || value.isempty()) return false; // refuse to parse invalid unit or empty string int num_decimals = decimals(unit); // ignore spaces and thin spaces when parsing qstringlist parts = removespaces(value).split("."); 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 = whole + decimals.leftjustified(num_decimals, '0'); if(str.size() > 18) { return false; // longer numbers will exceed 63 bits } camount retvalue(str.tolonglong(&ok)); if(val_out) { *val_out = retvalue; } return ok; }