mc icon indicating copy to clipboard operation
mc copied to clipboard

Support precision width for formatting floats

Open wasamasa opened this issue 6 years ago • 2 comments

std.fmt does currently only offer the "w" and "p" flags for ensuring a minimum width and padding to that width. Something equivalent to "%.2f" in C would be nice to have, such a flag would set the exact width of the digits after the decimal point. There's a bit of complication in C mandating that rounding must happen and that a precision of zero is handled specially by not printing a decimal point at all.

wasamasa avatar Jul 23 '18 08:07 wasamasa

Sorry, been pretty busy, haven't had a chance to get to this yet. However, for reference, the Ryu algorithm (https://github.com/ulfjack/ryu) also came out recently. TODO: Implement it and replace dragon4.

oridb avatar Aug 06 '18 20:08 oridb

Note that I still don't have any idea or preference on what to name the precision flag. The obvious choice of "p" is already taken. Modula-3 uses a "prec" keyword, but that would look odd next to the single-letter ones. "f" would be easy to remember.

wasamasa avatar Aug 06 '18 20:08 wasamasa