tags:

views:

179

answers:

1

Is there a way to force showing the + sign in front of positive numbers when using StringFormat?

For example:

<TextBlock Text="{Binding Path=PercentAgainstBudget, 
                          StringFormat={}{0:0.00}%}" />

If PercentAgainstBudget is negative I see the - sign. But if its positive, it does not. Since this number is an offset, I'd like to force showing +/-. I could make a ValueConverter but I'm wondering if there's a way to do it through the StringFormat property.

+8  A: 

The format string can be made of two parts separated by a semicolon. First part is the format of positive numbers, second of negative. You'll want this: +0.0%;-0.0%

PS C:\Users\jachymko> '{0:+0.0%;-0.0%}' -f 2.45
+245,0%
PS C:\Users\jachymko> '{0:+0.0%;-0.0%}' -f -2.45
-245,0%
jachymko