-
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
Double.ToString with two section separators and negative zero placing additional negative sign in output #70460
Comments
Tagging subscribers to this area: @dotnet/area-system-numerics Issue DetailsDescriptionWhen using a string format with two section separators and a negative zeroish number when accounting for the limited number of decimal points, there is an additional negative sign added to the output string when there shouldn't be. Reproduction Steps
Expected behaviorOutputs Actual behavioroutputs Regression?This worked in .NET Framework 4.7.2. Known WorkaroundsThe two-section "+0.00;-0.00" can be replaced by the three-section "+0.00;-0.00;+0.00" and seems to work correctly ConfigurationI've reproduced this in both my local visual studio and dotnetfiddle.net on dotnet 6. Other informationThis seems related to the bug #32237 which was an "Closed As Design" due to https://devblogs.microsoft.com/dotnet/floating-point-parsing-and-formatting-improvements-in-net-core-3-0/, but this issue seems like an actual regression since the string format is explicitly calling out how to format positive and negative numbers
|
This was "+0.00" in .NET Core 2.1 and changed to "-+0.00" in .NET Core 3.1 |
I'm guessing there is a conflict between the input value and the rounded value. Will take a look. |
Depending on your use case, it's possible to work around it using all three section separators, but you lose the ability to print negative and positive zero differently. For example: (-0.0).ToString("+0.0;-0.0;0.0") and (-0.0000001).ToString("+0.0;-0.0;0.0") both display |
The workaround we're using to preserve the behavior is in the issue. Your idea will display "0.0" instead of "+0.0" (or "-0.0") which isn't the right size since the protocol requires a sign bit in that position of the string. |
Ah, I see I didn't read that properly (it was late at night :) ). You're right, that is the better workaround. Any of these workaround using the third section still have the problem of not preserving the difference between -0.0 and +0.0 though -- therefore there is no real workaround if you really need that behavior (other than writing your own formatting code). A true fix would be great. |
This is effectively a do anytime issue. The bug is small and shouldn't be overly difficult to fix. For the most part |
Description
When using a string format with two section separators and a negative zeroish number when accounting for the limited number of decimal points, there is an additional negative sign added to the output string when there shouldn't be.
Reproduction Steps
Console.WriteLine((-0.001).ToString("+0.00;-0.00"));
,Expected behavior
Outputs
+0.00
on .NET Framework 4.7.2 (-0.00
seems valid as well)Actual behavior
outputs
-+0.00
on dotnet6Regression?
This worked in .NET Framework 4.7.2.
Known Workarounds
The two-section "+0.00;-0.00" can be replaced by the three-section "+0.00;-0.00;+0.00" and seems to work correctly
Configuration
I've reproduced this in both my local visual studio and dotnetfiddle.net on dotnet 6.
Other information
This seems related to the bug #32237 which was an "Closed As Design" due to https://devblogs.microsoft.com/dotnet/floating-point-parsing-and-formatting-improvements-in-net-core-3-0/, but this issue seems like an actual regression since the string format is explicitly calling out how to format positive and negative numbers
The text was updated successfully, but these errors were encountered: