Ejemplo n.º 1
0
QString EkwicoinUnits::format(int unit, qint64 n, 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 coin = factor(unit);
    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-stule separators as these are locale indendent and can't be
    // confused with the decimal marker.  Rule is to use a thin space every
    // three digits on *both* sides of the decimal point - but only if there
    // are five or more digits
    QChar thin_sp(THIN_SP_CP);
    int q_size = quotient_str.size();
    if (separators == separatorAlways || (separators == separatorStandard && q_size > 4))
        for (int i = 3; i < q_size; i += 3)
            quotient_str.insert(q_size - i, thin_sp);

    int r_size = remainder_str.size();
    if (separators == separatorAlways || (separators == separatorStandard && r_size > 4))
        for (int i = 3, adj = 0; i < r_size ; i += 3, adj++)
            remainder_str.insert(i + adj, thin_sp);

    if (n < 0)
        quotient_str.insert(0, '-');
    else if (fPlus && n > 0)
        quotient_str.insert(0, '+');
    return quotient_str + QString(".") + remainder_str;
}
qstring moorecoinunits::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);
    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.
    qchar thin_sp(thin_sp_cp);
    int q_size = quotient_str.size();
    if (separators == separatoralways || (separators == separatorstandard && q_size > 4))
        for (int i = 3; i < q_size; i += 3)
            quotient_str.insert(q_size - i, thin_sp);

    if (n < 0)
        quotient_str.insert(0, '-');
    else if (fplus && n > 0)
        quotient_str.insert(0, '+');
    return quotient_str + qstring(".") + remainder_str;
}
Ejemplo n.º 3
0
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);
    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.
    QChar thin_sp(THIN_SP_CP);
    int q_size = quotient_str.size();
    if (separators == separatorAlways || (separators == separatorStandard && q_size > 4))
        for (int i = 3; i < q_size; i += 3)
            quotient_str.insert(q_size - i, thin_sp);

    if (n < 0)
        quotient_str.insert(0, '-');
    else if (fPlus && n > 0)
        quotient_str.insert(0, '+');
    return quotient_str + QString(".") + remainder_str;
}
    QString textFromValue(double value) const
    {
        QStringList parts = QDoubleSpinBox::textFromValue(value).split(".");
        QString quotient_str = parts[0];
        QString remainder_str;
        if(parts.size() > 1)
            remainder_str = parts[1];

        // Code duplication between here and BitcoinUnits::format
        // TODO: Figure out how to share this code
        QChar thin_sp(THIN_SP_CP);
        int q_size = quotient_str.size();
        if (q_size > 4)
            for (int i = 3; i < q_size; i += 3)
                quotient_str.insert(q_size - i, thin_sp);

        int r_size = remainder_str.size();
        if (r_size > 4)
            for (int i = 3, adj = 0; i < r_size; i += 3, adj++)
                remainder_str.insert(i + adj, thin_sp);

        if(remainder_str.isEmpty())
            return quotient_str;
        else
            return quotient_str + QString(".") + remainder_str;
    }