From d60ae82a25f815ec642c21109f35277c4151d1ab Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Sat, 16 Mar 2024 21:35:19 +0000 Subject: [PATCH] Drop the 2 decimal places when printing values in bytes When printing a number of bytes using Utils::format_size() it always formatted the value with 2 decimal digits and an IEC multiplier. This can be seen in the details of any operation which includes clearing old file system signatures. Fragment of operation details: Format /dev/sdb1 as cleared + calibrate /dev/sdb1 + clear old file system signatures in /dev/sdb1 write 512.00 KiB of zeros at byte offset 0 write 4.00 KiB of zeros at byte offset 67108864 >> write 512.00 B of zeros at byte offset 132537184 write 4.00 KiB of zeros at byte offset 1072693248 write 512.00 KiB of zeros at byte offset 133593440 flush operating system cache of /dev/sdb1 It doesn't make sense to be reporting 100ths of a byte. So when values are below 1 KiB report numbers of bytes without any decimal digits. --- src/Utils.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Utils.cc b/src/Utils.cc index 2bc92269..4715efff 100644 --- a/src/Utils.cc +++ b/src/Utils.cc @@ -535,14 +535,17 @@ bool Utils::kernel_version_at_least( int major_ver, int minor_ver, int patch_ver Glib::ustring Utils::format_size( Sector sectors, Byte_Value sector_size ) { std::stringstream ss ; - ss << std::setiosflags( std::ios::fixed ) << std::setprecision( 2 ) ; + ss << std::setiosflags(std::ios::fixed); if ( (sectors * sector_size) < KIBIBYTE ) { + ss << std::setprecision(0); ss << sector_to_unit( sectors, sector_size, UNIT_BYTE ) ; return Glib::ustring::compose( _("%1 B"), ss .str() ) ; } - else if ( (sectors * sector_size) < MEBIBYTE ) + + ss << std::setprecision(2); + if (sectors * sector_size < MEBIBYTE) { ss << sector_to_unit( sectors, sector_size, UNIT_KIB ) ; return Glib::ustring::compose( _("%1 KiB"), ss .str() ) ;