Open
Description
Type of issue
Code doesn't work
Description
I was tinkering with names and layout, so I am providing what I think are the only the applicable parts, but not my actual revised code.
Basically: Calculate vs. hard code the middle sign. Use the calculated sign in the middle. Suppress the sign on the Imaginary part. Cover both the 'i' and 'j' case.
Sample code:
If fmt.Substring(0, 1).Equals("I", StringComparison.OrdinalIgnoreCase) Then
Return c1.Real.ToString(fmtString) + " + " + 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"
Else
Return c1.ToString(fmt, provider)
End If
Suggestion:
' Determine the sign to display.
dim sign=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) + " " + sign + " " + math,abs(c1.Imaginary).ToString(fmtString) + "i"
ElseIf fmt.Substring(0, 1).Equals("J", StringComparison.OrdinalIgnoreCase) Then
Return c1.Real.ToString(fmtString) + " + " + math.abs(c1.Imaginary).ToString(fmtString) + "j"
Else
Return c1.ToString(fmt, provider)
End If
Maybe this should be its own case, but, while here, only some of the sample outputs have been updated to the ToString change.
"(12.3000001907349, 0)" vs. "<12.10; 15.40>".
Page URL
Content source URL
Document Version Independent Id
a7805572-1e26-d823-aa06-0ad20172ab6a
Platform Id
aba02a42-6ce7-1e75-8ca1-d4667deec955
Article author
Metadata
- ID: f1c6acac-5557-c431-8318-e93f55b9dd4e
- PlatformId: aba02a42-6ce7-1e75-8ca1-d4667deec955
- Service: dotnet-fundamentals
Metadata
Metadata
Labels
Type
Projects
Status
👀 In review