dotnet/runtime

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

Open

#70,460 建立於 2022年6月8日

在 GitHub 查看
 (7 留言) (2 反應) (1 負責人)C# (5,445 fork)batch import
area-System.Numericsbughelp wanted

倉庫指標

Star
 (17,886 star)
PR 合併指標
 (平均合併 12天 11小時) (30 天內合併 661 個 PR)

描述

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

貢獻者指南