diff --git a/src/libsync/utility.cpp b/src/libsync/utility.cpp index 6fca88232..613c7affb 100644 --- a/src/libsync/utility.cpp +++ b/src/libsync/utility.cpp @@ -113,6 +113,10 @@ QString Utility::octetsToString( qint64 octets ) QString s; qreal value = octets; + // Whether we care about decimals: only for GB and only + // if it's less than 10 GB. + bool round = true; + // do not display terra byte with the current units, as when // the MB, GB and KB units were made, there was no TB, // see the JEDEC standard @@ -120,6 +124,7 @@ QString Utility::octetsToString( qint64 octets ) if (octets >= gb) { s = QCoreApplication::translate("Utility", "%L1 GB"); value /= gb; + round = false; } else if (octets >= mb) { s = QCoreApplication::translate("Utility", "%L1 MB"); value /= mb; @@ -130,7 +135,13 @@ QString Utility::octetsToString( qint64 octets ) s = QCoreApplication::translate("Utility", "%L1 B"); } - return (value > 9.95) ? s.arg(qRound(value)) : s.arg(value, 0, 'g', 2); + if (value > 9.95) + round = true; + + if (round) + return s.arg(qRound(value)); + + return s.arg(value, 0, 'g', 2); } // Qtified version of get_platforms() in csync_owncloud.c diff --git a/test/testutility.h b/test/testutility.h index e8ce07528..bc7cc4d6c 100644 --- a/test/testutility.h +++ b/test/testutility.h @@ -31,14 +31,14 @@ private slots: QLocale::setDefault(QLocale("en")); QCOMPARE(octetsToString(999) , QString("999 B")); QCOMPARE(octetsToString(1024) , QString("1 KB")); - QCOMPARE(octetsToString(1364) , QString("1.3 KB")); + QCOMPARE(octetsToString(1364) , QString("1 KB")); - QCOMPARE(octetsToString(9110) , QString("8.9 KB")); - QCOMPARE(octetsToString(9910) , QString("9.7 KB")); + QCOMPARE(octetsToString(9110) , QString("9 KB")); + QCOMPARE(octetsToString(9910) , QString("10 KB")); QCOMPARE(octetsToString(10240) , QString("10 KB")); QCOMPARE(octetsToString(123456) , QString("121 KB")); - QCOMPARE(octetsToString(1234567) , QString("1.2 MB")); + QCOMPARE(octetsToString(1234567) , QString("1 MB")); QCOMPARE(octetsToString(12345678) , QString("12 MB")); QCOMPARE(octetsToString(123456789) , QString("118 MB")); QCOMPARE(octetsToString(1000LL*1000*1000 * 5) , QString("4.7 GB"));