#How do i make integer formatting not put the + number sign?
1 messages · Page 1 of 1 (latest)
Is it possible for the numbers to ever be negative? Based on my understanding of std.fmt.formatInt (https://github.com/ziglang/zig/blob/bf5ab54510fd8fbd300ddc22f9af4767477be0e5/lib/std/fmt.zig#L1443-L1455), the + will be printed for signed integer types whenever the width is non-zero, but unsigned types will not include the sign
the numebrs can never be negative, but its quite ugly to cast to unsigned for every single parameter
is there no better way to make it Not do that?
count could be an []u32 or whatever.
But I agree that format behavior is annoying.
count is an []i32, i dont have control over the type here
im reading a file format which itself uses negative numbers to convey information, but its never displayed
Ah, OK, my next suggestion was going to be to see if it's possible to just change the underlying type to unsigned, but it sounds like it's not. Another option might be to create a custom formatter function (example: https://github.com/ziglang/zig/blob/bf5ab54510fd8fbd300ddc22f9af4767477be0e5/lib/std/fmt.zig#L838-L881) which always does what you want it to do, even for signed integers, though this isn't ideal
If you give it a really short name like n4 or something, it wouldn't be too much more to type:
std.debug.print("{}\n", .{n4(some_number)});
i'll probably just do the cast and open an issue to make this behaviour configurable somehow, its very unexpected for when i pad by 0s for it to randomly toss a + in the middle for the sign
Yeah, I agree, hopefully a future version of std.fmt can accept something like a sign or variant option as supported in some other similar formatting libraries