Fixed rounding bugs with floating numbers v2.

This commit is contained in:
sledgehammer999 2013-09-14 15:15:30 +03:00
parent fcebe1e485
commit 70215bd3ff
2 changed files with 19 additions and 19 deletions

View file

@ -1128,10 +1128,12 @@ void MainWindow::updateGUI() {
html += "qBittorrent";
html += "</div>";
html += "<div style='vertical-align: baseline; height: 18px;'>";
html += "<img src=':/Icons/skin/download.png'/>&nbsp;"+tr("DL speed: %1 KiB/s", "e.g: Download speed: 10 KiB/s").arg(QString::number(QBtSession::instance()->getPayloadDownloadRate()/1024., 'f', 1));
/* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9
** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 */
html += "<img src=':/Icons/skin/download.png'/>&nbsp;"+tr("DL speed: %1 KiB/s", "e.g: Download speed: 10 KiB/s").arg(QString::number((int)((QBtSession::instance()->getPayloadDownloadRate()/1024.)*10)/10.0, 'f', 1));
html += "</div>";
html += "<div style='vertical-align: baseline; height: 18px;'>";
html += "<img src=':/Icons/skin/seeding.png'/>&nbsp;"+tr("UP speed: %1 KiB/s", "e.g: Upload speed: 10 KiB/s").arg(QString::number(QBtSession::instance()->getPayloadUploadRate()/1024., 'f', 1));
html += "<img src=':/Icons/skin/seeding.png'/>&nbsp;"+tr("UP speed: %1 KiB/s", "e.g: Upload speed: 10 KiB/s").arg(QString::number((int)((QBtSession::instance()->getPayloadUploadRate()/1024.)*10)/10.0, 'f', 1));
html += "</div>";
#else
// OSes such as Windows do not support html here

View file

@ -78,11 +78,9 @@ public:
QStyleOptionProgressBarV2 newopt;
qreal progress = index.data().toDouble()*100.;
newopt.rect = opt.rect;
// We don't want to display 100% unless
// the torrent is really complete
if (progress > 99.94 && progress < 100.)
progress = 99.9;
newopt.text = QString(QByteArray::number(progress, 'f', 1))+QString::fromUtf8("%");
/* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9
** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 */
newopt.text = QString::number((int)(progress*10)/10.0, 'f', 1)+"%";
newopt.progress = (int)progress;
newopt.maximum = 100;
newopt.minimum = 0;