diff --git a/docs/fundamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/csharp/Project.csproj b/docs/fundamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/csharp/Project.csproj
index 5ed8f36be8cd5..7e1f97164f052 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/csharp/Project.csproj
+++ b/docs/fundamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/csharp/Project.csproj
@@ -2,7 +2,7 @@
Exe
- net9
+ net9.0
diff --git a/docs/fundamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/csharp/customfmt1.cs b/docs/fundamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/csharp/customfmt1.cs
index 496a4a4e92f6f..6040075babea1 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/csharp/customfmt1.cs
+++ b/docs/fundamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/csharp/customfmt1.cs
@@ -33,9 +33,19 @@ public string Format(string format, object arg,
fmtString = "N" + precision.ToString();
}
if (format.Substring(0, 1).Equals("I", StringComparison.OrdinalIgnoreCase))
- return c1.Real.ToString(fmtString) + " + " + c1.Imaginary.ToString(fmtString) + "i";
+ {
+ // Determine the sign to display.
+ char sign = c1.Imaginary < 0 ? '-' : '+';
+ // Display the determined sign and the absolute value of the imaginary part.
+ return c1.Real.ToString(fmtString) + " " + sign + " " + Math.Abs(c1.Imaginary).ToString(fmtString) + "i";
+ }
else if (format.Substring(0, 1).Equals("J", StringComparison.OrdinalIgnoreCase))
- return c1.Real.ToString(fmtString) + " + " + c1.Imaginary.ToString(fmtString) + "j";
+ {
+ // Determine the sign to display.
+ char sign = c1.Imaginary < 0 ? '-' : '+';
+ // Display the determined sign and the absolute value of the imaginary part.
+ return c1.Real.ToString(fmtString) + " " + sign + " " + Math.Abs(c1.Imaginary).ToString(fmtString) + "j";
+ }
else
return c1.ToString(format, provider);
}
diff --git a/docs/fundamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/vb/Project.vbproj b/docs/fundamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/vb/Project.vbproj
index 5ed8f36be8cd5..7e1f97164f052 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/vb/Project.vbproj
+++ b/docs/fundamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/vb/Project.vbproj
@@ -2,7 +2,7 @@
Exe
- net9
+ net9.0
diff --git a/docs/fundamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/vb/customfmt1.vb b/docs/fundamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/vb/customfmt1.vb
index ee1efcfb2401b..61ee5de6b18c6 100644
--- a/docs/fundamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/vb/customfmt1.vb
+++ b/docs/fundamentals/runtime-libraries/snippets/System.Numerics/Complex/Overview/vb/customfmt1.vb
@@ -32,10 +32,13 @@ Public Class ComplexFormatter
End Try
fmtString = "N" + precision.ToString()
End If
+ ' Determine the sign to display.
+ Dim sign As Char = If(c1.Imaginary < 0.0, "-"c, "+"c)
+ ' Display the determined sign and the absolute value of the imaginary part.
If fmt.Substring(0, 1).Equals("I", StringComparison.OrdinalIgnoreCase) Then
- Return c1.Real.ToString(fmtString) + " + " + c1.Imaginary.ToString(fmtString) + "i"
+ Return c1.Real.ToString(fmtString) + " " + sign + " " + Math.Abs(c1.Imaginary).ToString(fmtString) + "i"
ElseIf fmt.Substring(0, 1).Equals("J", StringComparison.OrdinalIgnoreCase) Then
- Return c1.Real.ToString(fmtString) + " + " + c1.Imaginary.ToString(fmtString) + "j"
+ Return c1.Real.ToString(fmtString) + " " + sign + " " + Math.Abs(c1.Imaginary).ToString(fmtString) + "j"
Else
Return c1.ToString(fmt, provider)
End If