-
Notifications
You must be signed in to change notification settings - Fork 13k
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
extend fmt! to add %g analogous to printf '%g' #3810
Comments
I don't think this is a backwards compatibility issue. Nominating for recategorization. |
just a bug, removing milestone/nomination. |
Visiting for triage, email from 2013 sep 23 We're deprecated Its not 100% clear from the |
I wrote some test code. The If this were a dynamically typed language (like Lisp or JavaScript), I'd file a bug saying that its important to distinguish exact integers from inexact (floating-point) values that look like integers. But we're statically typed, so that argument does not hold up. (I do wonder whether some people might want a way to specify that the decimal point and at least one trailing decimal is always output. But it seems like that should be filed as a separate bug at this point.) Felix's test code followsfn main() {
macro_rules! demo(
($fmt:expr, $num:expr) =>
( println!("demo format!({:>9s}, {:>21s}) \t=> {:s}",
format!("\"{:s}\"", $fmt), stringify!($num), format!($fmt, $num)) )
)
demo!( "{}", 1.00);
demo!( "{:f}", 1.00);
demo!( "{:0f}", 1.00);
demo!("{:0.0f}", 1.00);
demo!("{:0.1f}", 1.00);
demo!("{:0.2f}", 1.00);
demo!( "{:f}", 1.20);
demo!( "{:0f}", 1.20);
demo!( "{:02f}", 1.20);
demo!( "{:20f}", 1.20);
demo!( "{:08f}", 1.20);
demo!( "{:.3f}", 1.20);
demo!( "{:0.f}", 1.20);
demo!( "{:+f}", 1.20);
demo!( "{:.1f}", 1.20);
demo!( "{:.2f}", 1.20);
demo!( "{:.3f}", 1.20);
demo!( "{:.4f}", 1.20);
demo!( "{:.1f}", 1.24);
demo!( "{:.2f}", 1.24);
demo!( "{:.3f}", 1.24);
demo!( "{:.4f}", 1.24);
demo!( "{:.1f}", 1.25);
demo!( "{:.2f}", 1.25);
demo!( "{:.3f}", 1.25);
demo!( "{:.4f}", 1.25);
demo!( "{:.1f}", 1.26);
demo!( "{:.2f}", 1.26);
demo!( "{:.3f}", 1.26);
demo!( "{:.4f}", 1.26);
demo!( "{:f}", 1.123456789123456789f);
demo!( "{:.0f}", 1.123456789123456789f);
demo!("{:0.0f}", 1.123456789123456789f);
demo!("{:0.1f}", 1.123456789123456789f);
demo!( "{:.1f}", 1.123456789123456789f);
demo!("{:6.1f}", 1.123456789123456789f);
demo!("{:6.3f}", 1.123456789123456789f);
demo!( "{:.8f}", 1.123456789123456789f);
demo!("{:.20f}", 1.123456789123456789f);
} |
(closing as "fixed" since |
I was misreading the man page for This is a demonstration from python:
I'm not sure we want to provide this option, but I'll leave the ticket open in case others want to comment. (Also, I do not think |
Triage. |
Triage: nothing has changed, still not sure we actually want this feature. |
I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized. This issue has been moved to the RFCs repo: rust-lang/rfcs#844 |
fix erroneous flattening of `{self}` in imports
It's sometimes nice not to include trailing zeroes when printing floats. It'd be nice if we copied printf's %g to handle this.
The text was updated successfully, but these errors were encountered: