Commit 7a9635555b

marleck55 <40122305+marleck55@users.noreply.github.com>
2018-06-09 18:05:58
std/fmt: Use lowercase k for kilo in base 1000 (#1090)
1 parent 670a0a3
Changed files (1)
std
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);