From 75cead9266d15ed16b98e53ac4aa4ccaf72fcdb8 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 29 Nov 2020 20:16:14 +0800 Subject: [PATCH] Avoid potential rounding to integer issues --- src/gui/torrentcontentmodelitem.cpp | 9 +++------ src/gui/transferlistmodel.cpp | 7 +++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/gui/torrentcontentmodelitem.cpp b/src/gui/torrentcontentmodelitem.cpp index 71c58b8d7..34ebe498c 100644 --- a/src/gui/torrentcontentmodelitem.cpp +++ b/src/gui/torrentcontentmodelitem.cpp @@ -126,12 +126,9 @@ QString TorrentContentModelItem::displayData(const int column) const return tr("Normal", "Normal (priority)"); } case COL_PROGRESS: - { - const qreal progress = m_progress * 100; - return (static_cast(progress) == 100) - ? QString::fromLatin1("100%") - : (Utils::String::fromDouble(progress, 1) + QLatin1Char('%')); - } + return (m_progress >= 1) + ? QString::fromLatin1("100%") + : (Utils::String::fromDouble((m_progress * 100), 1) + QLatin1Char('%')); case COL_SIZE: return Utils::Misc::friendlyUnit(m_size); case COL_REMAINING: diff --git a/src/gui/transferlistmodel.cpp b/src/gui/transferlistmodel.cpp index f4992b8ea..5f70411d9 100644 --- a/src/gui/transferlistmodel.cpp +++ b/src/gui/transferlistmodel.cpp @@ -316,12 +316,11 @@ QString TransferListModel::displayValue(const BitTorrent::TorrentHandle *torrent return tagsList.join(", "); }; - const auto progressString = [](qreal progress) -> QString + const auto progressString = [](const qreal progress) -> QString { - progress *= 100; - return (static_cast(progress) == 100) + return (progress >= 1) ? 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