Skip to content

%+f printf format specifier adds both plus and minus for negative zero (-0) on .NET Core #15557

Description

@jwosty

printf formatting a value of -0.0 with a %f format specifier and setting the + flag adds a plus and a minus sign to the result.

sprintf "%f" +0.0 // 0.000000 (correct)
sprintf "%f" -0.0 // -0.000000 (correct)
sprintf "%f" -0.0000001 // -0.000000 (correct)
sprintf "%+f" +0.0 // +0.000000 (correct)
sprintf "%+f" -0.0 // +-0.000000 (incorrect)
sprintf "%+f" -0.0000001 // -0.000000 (correct)

Expected behavior

.NET Core: sprintf "%+f" -0.0 should display -0.000000 (matching .NET Core Double.ToString())
.NET Framework: sprintf "%+f" -0.0 should display +0.000000 (matching .NET Framework Double.ToString())

Original text `sprintf "%+f" -0.0` should display `-0.000000` `sprintf "%+f" -0.0` should display `+0.000000` (to match .NET Framework behavior).

Actual behavior

Displays +-0.000000

Known workarounds

None known.

Related information

Potentially related to: dotnet/runtime#70460

  • macOS 12.6
  • .NET 6.0.15

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-LibraryIssues for FSharp.Core not covered elsewhereBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    Projects

    Status
    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions