Reputation: 20468
I have a string.Format
like this :
string Test = string.Format("{0:#,0}", NegativeNumber);
how can I change the negative sign position (Direction -> left or right)?
Upvotes: 3
Views: 4346
Reputation: 13589
The easiest route might be to just have a different format for negative numbers
string Test = string.Format("{0:#,0;#,0-}", NegativeNumber);
Results:
PS C:\> '{0:#,0;#,0-}' -f -17.2
17-
PS C:\> '{0:#,0;#,0-}' -f 17.2
17
The semicolon
(;)
is a conditional format specifier that applies different formatting to a number depending on whether its value is positive, negative, or zero. To produce this behavior, a custom format string can contain up to three sections separated by semicolons. These sections are described in the following table.
Upvotes: 8