Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix display of bytes without decimals (#10594) #10595

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/core/Tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"});
Expand Down
2 changes: 1 addition & 1 deletion tests/TestTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading