Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support precision width for formatting floats #181

Open
wasamasa opened this issue Jul 23, 2018 · 2 comments
Open

Support precision width for formatting floats #181

wasamasa opened this issue Jul 23, 2018 · 2 comments

Comments

@wasamasa
Copy link

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.

@oridb
Copy link
Owner

oridb commented Aug 6, 2018

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.

@wasamasa
Copy link
Author

wasamasa commented Aug 6, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants