views:

44

answers:

2

how my dear friends:

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)?

thanks in future advance.

+1  A: 

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

http://msdn.microsoft.com/en-us/library/0c899ak8.aspx

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.

James Manning
thanks James Manning - solved
LostLord
A: 

Would this work:

String.Format("{0:0.00;0.00-;zero}", -123.4567); 
DiggyF