Skip to content

Double.ToString with two section separators and negative zero placing additional negative sign in output #70460

@fryguy1013

Description

@fryguy1013

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 dotnet6

Regression?

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions