dotnet/runtime

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

Open

#70,460 opened on 2022年6月8日

GitHub で見る
 (7 comments) (2 reactions) (1 assignee)C# (5,445 forks)batch import
area-System.Numericsbughelp wanted

Repository metrics

Stars
 (17,886 stars)
PR merge metrics
 (平均マージ 12d 11h) (30d で 661 merged PRs)

説明

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 https://github.com/dotnet/runtime/issues/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

コントリビューターガイド