Home > Enterprise >  C# .NET 5.0 - Formatter of the sign of negative decimals sometimes prints a plus
C# .NET 5.0 - Formatter of the sign of negative decimals sometimes prints a plus

Time:07-26

Consider this code:

Console.WriteLine($"{-0.4m: ;-; }");
Console.WriteLine($"{-0.5m: ;-; }");

It prints

 
-

Is this a .NET bug?

CodePudding user response:

I believe it's due to rounding according to the documentation:

If the number to be formatted is nonzero, but becomes zero after rounding according to the format in the first or second section, the resulting zero is formatted according to the third section.

  • Related