-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Text formatting: a leading zero on the minimum width should really mean leading zero #39997
Comments
Seems reasonable to me, as documented:
The precise definition of "sign aware" isn't really specified and this seems like a great interpretation to me (changing the first example above to |
Now it always implies right-alignment, so that padding zeroes are placed after the sign (if any) and before the digits. In other words, it always takes precedence over explicitly specified `[[fill]align]`. This also affects the '#' flag: zeroes are placed after the prefix (0b, 0o, 0x) and before the digits. :05 :<05 :>05 :^05 before |-0001| |-1000| |-0001| |-0100| after |-0001| |-0001| |-0001| |-0001| :#05x :<#05x :>#05x :^#05x before |0x001| |0x100| |000x1| |0x010| after |0x001| |0x001| |0x001| |0x001| Fixes rust-lang#39997 [breaking-change]
Change how the `0` flag works in format! Now it always implies right-alignment, so that padding zeroes are placed after the sign (if any) and before the digits. In other words, it always takes precedence over explicitly specified `[[fill]align]`. This also affects the '#' flag: zeroes are placed after the prefix (0b, 0o, 0x) and before the digits. Here's a short summary of how similar format strings work in Python and Rust: ``` :05 :<05 :>05 :^05 Python 3.6 |-0001| |-1000| |000-1| |0-100| Rust before |-0001| |-1000| |-0001| |-0100| Rust after |-0001| |-0001| |-0001| |-0001| :#05x :<#05x :>#05x :^#05x Python 3.6 |0x001| |0x100| |000x1| |00x10| Rust before |0x001| |0x100| |000x1| |0x010| Rust after |0x001| |0x001| |0x001| |0x001| ``` Fixes rust-lang#39997 [breaking-change]
Change how the `0` flag works in format! Now it always implies right-alignment, so that padding zeroes are placed after the sign (if any) and before the digits. In other words, it always takes precedence over explicitly specified `[[fill]align]`. This also affects the '#' flag: zeroes are placed after the prefix (0b, 0o, 0x) and before the digits. Here's a short summary of how similar format strings work in Python and Rust: ``` :05 :<05 :>05 :^05 Python 3.6 |-0001| |-1000| |000-1| |0-100| Rust before |-0001| |-1000| |-0001| |-0100| Rust after |-0001| |-0001| |-0001| |-0001| :#05x :<#05x :>#05x :^#05x Python 3.6 |0x001| |0x100| |000x1| |00x10| Rust before |0x001| |0x100| |000x1| |0x010| Rust after |0x001| |0x001| |0x001| |0x001| ``` Fixes rust-lang#39997 [breaking-change]
Change how the `0` flag works in format! Now it always implies right-alignment, so that padding zeroes are placed after the sign (if any) and before the digits. In other words, it always takes precedence over explicitly specified `[[fill]align]`. This also affects the '#' flag: zeroes are placed after the prefix (0b, 0o, 0x) and before the digits. Here's a short summary of how similar format strings work in Python and Rust: ``` :05 :<05 :>05 :^05 Python 3.6 |-0001| |-1000| |000-1| |0-100| Rust before |-0001| |-1000| |-0001| |-0100| Rust after |-0001| |-0001| |-0001| |-0001| :#05x :<#05x :>#05x :^#05x Python 3.6 |0x001| |0x100| |000x1| |00x10| Rust before |0x001| |0x100| |000x1| |0x010| Rust after |0x001| |0x001| |0x001| |0x001| ``` Fixes rust-lang#39997 [breaking-change]
Change how the `0` flag works in format! Now it always implies right-alignment, so that padding zeroes are placed after the sign (if any) and before the digits. In other words, it always takes precedence over explicitly specified `[[fill]align]`. This also affects the '#' flag: zeroes are placed after the prefix (0b, 0o, 0x) and before the digits. Here's a short summary of how similar format strings work in Python and Rust: ``` :05 :<05 :>05 :^05 Python 3.6 |-0001| |-1000| |000-1| |0-100| Rust before |-0001| |-1000| |-0001| |-0100| Rust after |-0001| |-0001| |-0001| |-0001| :#05x :<#05x :>#05x :^#05x Python 3.6 |0x001| |0x100| |000x1| |00x10| Rust before |0x001| |0x100| |000x1| |0x010| Rust after |0x001| |0x001| |0x001| |0x001| ``` Fixes rust-lang#39997 [breaking-change]
Change how the `0` flag works in format! Now it always implies right-alignment, so that padding zeroes are placed after the sign (if any) and before the digits. In other words, it always takes precedence over explicitly specified `[[fill]align]`. This also affects the '#' flag: zeroes are placed after the prefix (0b, 0o, 0x) and before the digits. Here's a short summary of how similar format strings work in Python and Rust: ``` :05 :<05 :>05 :^05 Python 3.6 |-0001| |-1000| |000-1| |0-100| Rust before |-0001| |-1000| |-0001| |-0100| Rust after |-0001| |-0001| |-0001| |-0001| :#05x :<#05x :>#05x :^#05x Python 3.6 |0x001| |0x100| |000x1| |00x10| Rust before |0x001| |0x100| |000x1| |0x010| Rust after |0x001| |0x001| |0x001| |0x001| ``` Fixes rust-lang#39997 [breaking-change]
#40729 is related and can be closed. |
In a string format, the leading zero on a minimum width is treated as a padding character. It would make more sense for it to be treated strictly as a leading zero. The status quo permits strange things like this:
Either
" 1"
or"0001"
would be better answers than one that changes the numeric value.Just to be clear, I agree that this behavior is correct:
This case uses
0
as its padding character, so you deserve whatever you get.The text was updated successfully, but these errors were encountered: