| ... | ... | @@ -911,8 +911,11 @@ fn formatSizeImpl(comptime base: comptime_int) type { |
| 911 | 911 | else => unreachable, |
| 912 | 912 | }; |
| 913 | 913 | |
| 914 | | const s = formatFloat(&buf, new_value, .{ .mode = .decimal, .precision = options.precision }) catch |err| switch (err) { |
| 915 | | error.BufferTooSmall => unreachable, |
| 914 | const s = switch (magnitude) { |
| 915 | 0 => buf[0..formatIntBuf(&buf, value, 10, .lower, .{})], |
| 916 | else => formatFloat(&buf, new_value, .{ .mode = .decimal, .precision = options.precision }) catch |err| switch (err) { |
| 917 | error.BufferTooSmall => unreachable, |
| 918 | }, |
| 916 | 919 | }; |
| 917 | 920 | |
| 918 | 921 | var i: usize = s.len; |
| ... | ... | @@ -2096,6 +2099,8 @@ test "filesize" { |
| 2096 | 2099 | try expectFmt("file size: 42B\n", "file size: {}\n", .{fmtIntSizeBin(42)}); |
| 2097 | 2100 | try expectFmt("file size: 63MB\n", "file size: {}\n", .{fmtIntSizeDec(63 * 1000 * 1000)}); |
| 2098 | 2101 | try expectFmt("file size: 63MiB\n", "file size: {}\n", .{fmtIntSizeBin(63 * 1024 * 1024)}); |
| 2102 | try expectFmt("file size: 42B\n", "file size: {:.2}\n", .{fmtIntSizeDec(42)}); |
| 2103 | try expectFmt("file size: 42B\n", "file size: {:>9.2}\n", .{fmtIntSizeDec(42)}); |
| 2099 | 2104 | try expectFmt("file size: 66.06MB\n", "file size: {:.2}\n", .{fmtIntSizeDec(63 * 1024 * 1024)}); |
| 2100 | 2105 | try expectFmt("file size: 60.08MiB\n", "file size: {:.2}\n", .{fmtIntSizeBin(63 * 1000 * 1000)}); |
| 2101 | 2106 | try expectFmt("file size: =66.06MB=\n", "file size: {:=^9.2}\n", .{fmtIntSizeDec(63 * 1024 * 1024)}); |