Avoid potential rounding to integer issues

This commit is contained in:
Chocobo1 2020-11-29 20:16:14 +08:00
parent 4381739b6d
commit 75cead9266
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
2 changed files with 6 additions and 10 deletions

View file

@ -126,12 +126,9 @@ QString TorrentContentModelItem::displayData(const int column) const
return tr("Normal", "Normal (priority)"); return tr("Normal", "Normal (priority)");
} }
case COL_PROGRESS: case COL_PROGRESS:
{ return (m_progress >= 1)
const qreal progress = m_progress * 100;
return (static_cast<int>(progress) == 100)
? QString::fromLatin1("100%") ? QString::fromLatin1("100%")
: (Utils::String::fromDouble(progress, 1) + QLatin1Char('%')); : (Utils::String::fromDouble((m_progress * 100), 1) + QLatin1Char('%'));
}
case COL_SIZE: case COL_SIZE:
return Utils::Misc::friendlyUnit(m_size); return Utils::Misc::friendlyUnit(m_size);
case COL_REMAINING: case COL_REMAINING:

View file

@ -316,12 +316,11 @@ QString TransferListModel::displayValue(const BitTorrent::TorrentHandle *torrent
return tagsList.join(", "); return tagsList.join(", ");
}; };
const auto progressString = [](qreal progress) -> QString const auto progressString = [](const qreal progress) -> QString
{ {
progress *= 100; return (progress >= 1)
return (static_cast<int>(progress) == 100)
? QString::fromLatin1("100%") ? QString::fromLatin1("100%")
: Utils::String::fromDouble(progress, 1) + '%'; : Utils::String::fromDouble((progress * 100), 1) + QLatin1Char('%');
}; };
const auto statusString = [this](const BitTorrent::TorrentState state, const QString &errorMessage) -> QString const auto statusString = [this](const BitTorrent::TorrentState state, const QString &errorMessage) -> QString