diff --git a/src/core/Tools.cpp b/src/core/Tools.cpp index 81fdd8e39..aa83305c4 100644 --- a/src/core/Tools.cpp +++ b/src/core/Tools.cpp @@ -138,7 +138,9 @@ namespace Tools i++; } - return QString("%1 %2").arg(QLocale().toString(size, 'f', precision), units.at(i)); + // do not display decimals for smallest unit bytes identified by index i==0 + const quint32 displayPrecision = (i == 0 ? 0 : precision); + return QString("%1 %2").arg(QLocale().toString(size, 'f', displayPrecision), units.at(i)); } QString humanReadableTimeDifference(qint64 seconds) diff --git a/tests/TestCli.cpp b/tests/TestCli.cpp index 2d020a7d5..f3fa69d89 100644 --- a/tests/TestCli.cpp +++ b/tests/TestCli.cpp @@ -2113,7 +2113,7 @@ void TestCli::testShow() "Tags: \n" "\n" "Attachments:\n" - " Sample attachment.txt (15.0 B)\n")); + " Sample attachment.txt (15 B)\n")); setInput("a"); execCmd(showCmd, {"show", m_dbFile->fileName(), "--show-attachments", "/Homebanking/Subgroup/Subgroup Entry"}); diff --git a/tests/TestTools.cpp b/tests/TestTools.cpp index 9aadfe0bf..f5c192f69 100644 --- a/tests/TestTools.cpp +++ b/tests/TestTools.cpp @@ -38,7 +38,7 @@ void TestTools::testHumanReadableFileSize() constexpr auto kibibyte = 1024u; using namespace Tools; - QCOMPARE(createDecimal("1", "00", "B"), humanReadableFileSize(1)); + QCOMPARE(QString("1 B"), humanReadableFileSize(1)); QCOMPARE(createDecimal("1", "00", "KiB"), humanReadableFileSize(kibibyte)); QCOMPARE(createDecimal("1", "00", "MiB"), humanReadableFileSize(kibibyte * kibibyte)); QCOMPARE(createDecimal("1", "00", "GiB"), humanReadableFileSize(kibibyte * kibibyte * kibibyte));