A common task is to print numbers using unit prefixes. In computing it is often sizes in bytes (such as "743 kB"), but also other quantities in science, engineering, etc, (such as "1.34 ns"). Therefore, I believe it will be beneficial to the whole community if facilities for formatting numbers with unit prefixes would be included in fmtlib and maybe even in the standard.
Hereafter I describe how do I see this feature:
- Add new formats for integer and floating point numbers, that would add a unit prefix after the number (the unit itself, such as "B", would has to be included into the format string outside and just after of the "{}" placeholder). The usage would be like:
fmt::print("{:.3?}B\n", 765432); // would produce "765.432 kB" fmt::print("{:.2?}s\n", 1.342784e-9); // would produce "1.34 ns"
- Support three options: decimal prefixes (1024 -> "1.024 k"), binary prefixes with "i" (1024 -> "1.000 Ki") and binary prefixes without "i" (1024 -> "1.000 k")