diff --git a/std/fmt/index.zig b/std/fmt/index.zig index bbf48df0cf60c8f26f0874e4d4aececc21b0884f..3844fbb10ad69cc8640be97aaefea184f1662829 100644 --- a/std/fmt/index.zig +++ b/std/fmt/index.zig @@ -559,14 +559,19 @@ pub fn formatBytes( return output(context, "0B"); } - const mags = " KMGTPEZY"; + const mags_si = " kMGTPEZY"; + const mags_iec = " KMGTPEZY"; const magnitude = switch (radix) { - 1000 => math.min(math.log2(value) / comptime math.log2(1000), mags.len - 1), - 1024 => math.min(math.log2(value) / 10, mags.len - 1), + 1000 => math.min(math.log2(value) / comptime math.log2(1000), mags_si.len - 1), + 1024 => math.min(math.log2(value) / 10, mags_iec.len - 1), else => unreachable, }; const new_value = f64(value) / math.pow(f64, f64(radix), f64(magnitude)); - const suffix = mags[magnitude]; + const suffix = switch (radix) { + 1000 => mags_si[magnitude], + 1024 => mags_iec[magnitude], + else => unreachable, + }; try formatFloatDecimal(new_value, width, context, Errors, output);