SI units: The unit is kB, not KB

This commit is contained in:
Henrik Bengtsson 2024-12-22 11:21:36 -08:00
parent 4873a7c765
commit db96bc698c
2 changed files with 7 additions and 7 deletions

2
ncdu.1
View file

@ -286,7 +286,7 @@ when given twice it will also add
thus ensuring that there is no way to modify the file system from within thus ensuring that there is no way to modify the file system from within
.Nm . .Nm .
.It Fl \-si , \-no\-si .It Fl \-si , \-no\-si
List sizes using base 10 prefixes, that is, powers of 1000 (KB, MB, etc), as List sizes using base 10 prefixes, that is, powers of 1000 (kB, MB, etc), as
defined in the International System of Units (SI), instead of the usual base 2 defined in the International System of Units (SI), instead of the usual base 2
prefixes (KiB, MiB, etc). prefixes (KiB, MiB, etc).
.It Fl \-disk\-usage , \-apparent\-size .It Fl \-disk\-usage , \-apparent\-size

View file

@ -419,7 +419,7 @@ pub const FmtSize = struct {
pub fn fmt(v: u64) FmtSize { pub fn fmt(v: u64) FmtSize {
if (main.config.si) { if (main.config.si) {
if (v < 1000) { return FmtSize.init(" B", v, 10, 1); } if (v < 1000) { return FmtSize.init(" B", v, 10, 1); }
else if (v < 999_950) { return FmtSize.init(" KB", v, 1, 100); } else if (v < 999_950) { return FmtSize.init(" kB", v, 1, 100); }
else if (v < 999_950_000) { return FmtSize.init(" MB", v, 1, 100_000); } else if (v < 999_950_000) { return FmtSize.init(" MB", v, 1, 100_000); }
else if (v < 999_950_000_000) { return FmtSize.init(" GB", v, 1, 100_000_000); } else if (v < 999_950_000_000) { return FmtSize.init(" GB", v, 1, 100_000_000); }
else if (v < 999_950_000_000_000) { return FmtSize.init(" TB", v, 1, 100_000_000_000); } else if (v < 999_950_000_000_000) { return FmtSize.init(" TB", v, 1, 100_000_000_000); }
@ -452,11 +452,11 @@ test "fmtsize" {
main.config.si = true; main.config.si = true;
try FmtSize.fmt( 0).testEql(" 0.0 B"); try FmtSize.fmt( 0).testEql(" 0.0 B");
try FmtSize.fmt( 999).testEql("999.0 B"); try FmtSize.fmt( 999).testEql("999.0 B");
try FmtSize.fmt( 1000).testEql(" 1.0 KB"); try FmtSize.fmt( 1000).testEql(" 1.0 kB");
try FmtSize.fmt( 1049).testEql(" 1.0 KB"); try FmtSize.fmt( 1049).testEql(" 1.0 kB");
try FmtSize.fmt( 1050).testEql(" 1.1 KB"); try FmtSize.fmt( 1050).testEql(" 1.1 kB");
try FmtSize.fmt( 999_899).testEql("999.9 KB"); try FmtSize.fmt( 999_899).testEql("999.9 kB");
try FmtSize.fmt( 999_949).testEql("999.9 KB"); try FmtSize.fmt( 999_949).testEql("999.9 kB");
try FmtSize.fmt( 999_950).testEql(" 1.0 MB"); try FmtSize.fmt( 999_950).testEql(" 1.0 MB");
try FmtSize.fmt( 1000_000).testEql(" 1.0 MB"); try FmtSize.fmt( 1000_000).testEql(" 1.0 MB");
try FmtSize.fmt( 999_850_009).testEql("999.9 MB"); try FmtSize.fmt( 999_850_009).testEql("999.9 MB");