Skip to content

Commit 7a96355

Browse files
marleck55andrewrk
authored andcommitted
std/fmt: Use lowercase k for kilo in base 1000 (#1090)
1 parent 670a0a3 commit 7a96355

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

std/fmt/index.zig

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,14 +559,19 @@ pub fn formatBytes(
559559
return output(context, "0B");
560560
}
561561

562-
const mags = " KMGTPEZY";
562+
const mags_si = " kMGTPEZY";
563+
const mags_iec = " KMGTPEZY";
563564
const magnitude = switch (radix) {
564-
1000 => math.min(math.log2(value) / comptime math.log2(1000), mags.len - 1),
565-
1024 => math.min(math.log2(value) / 10, mags.len - 1),
565+
1000 => math.min(math.log2(value) / comptime math.log2(1000), mags_si.len - 1),
566+
1024 => math.min(math.log2(value) / 10, mags_iec.len - 1),
566567
else => unreachable,
567568
};
568569
const new_value = f64(value) / math.pow(f64, f64(radix), f64(magnitude));
569-
const suffix = mags[magnitude];
570+
const suffix = switch (radix) {
571+
1000 => mags_si[magnitude],
572+
1024 => mags_iec[magnitude],
573+
else => unreachable,
574+
};
570575

571576
try formatFloatDecimal(new_value, width, context, Errors, output);
572577

0 commit comments

Comments
 (0)