-
Notifications
You must be signed in to change notification settings - Fork 4.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
Conditional format specifier and negative zero #13712
Comments
The first issue described is by design. The second issue described is a bug, it should print |
On .NET Core 2.2, Mono and .NET Framework 4.7.2, it prints The table produced by https://dotnetfiddle.net/vvAymM found some other differences: - .NET Core 3.0
+ .NET Core 2.2, Mono and .NET Framework 4.7.2
-(-0.1).ToString("p#;n#"): -p
-(-0.1).ToString("p0#;n0#"): -p00
-(-0.1).ToString("p1#;n1#"): -p1
+(-0.1).ToString("p#;n#"): p
+(-0.1).ToString("p0#;n0#"): p00
+(-0.1).ToString("p1#;n1#"): p1
-(-0.01).ToString("p#;n#"): -p
-(-0.01).ToString("p0#;n0#"): -p00
-(-0.01).ToString("p1#;n1#"): -p1
-(-0.01).ToString("p0.#;n0.#"): -p0
-(-0.01).ToString("p1.#;n1.#"): -p1
+(-0.01).ToString("p#;n#"): p
+(-0.01).ToString("p0#;n0#"): p00
+(-0.01).ToString("p1#;n1#"): p1
+(-0.01).ToString("p0.#;n0.#"): p0
+(-0.01).ToString("p1.#;n1.#"): p1 |
I realize now that I can use Regarding the second issue, would it make sense for the comments at https://github.com/dotnet/coreclr/blob/818b35978a1681690988b2c9c3f0b6a034d91e82/src/System.Private.CoreLib/shared/System/Number.Formatting.cs#L222-L225 and https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings#the--section-separator to be updated if they are not going to be followed in .NET Core? Thank you. |
Yes, the documentation should likely be updated as well. |
Tagging subscribers to this area: @tannergooding |
The documentation has already been updated:
|
@huoyaoyuan I see that the bug confirmed by @tannergooding is still present in .NET 7: Also, when that is fixed, the documentation you quoted will not be correct. It says, "If the number to be formatted is negative, but becomes zero after rounding according to the format in the second section, the resulting zero is formatted according to the first section." But here we have Thanks. |
Sorry I didn't test this locally. Can you confirm the behavior in .NET 7? Could you also examine the expected behavior according to doc? |
@huoyaoyuan I tested it in .NET 7, and The underlying issue is that the intended spec has changed as of .NET Core 3.0. Negative zero is now presented as |
I am looking for a way to make something like
(-0.01).ToString("0.#;-0.#")
produce"0"
. In .NET Core 3.0, it produces"-0"
. This makes the conditional format specifier unusable for me.During my experimentation, I noticed that
(-0.01).ToString("p0.#;n0.#")
produces"-p0"
. Thus, it seems that the statement "negative values are always displayed without a minus sign when section separators are used" at https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings#the--section-separator is not followed here.The text was updated successfully, but these errors were encountered: