c# – XAML StringFormat syntax for decimal places in WPF

Updated on     Kisan Patel

Problem:

How to use StringFormat syntax for decimal places in WPF?
WPF: Textbox Binding with StringFormat={}{0:F2}. Don’t show zero’s
How can I format a decimal bound to TextBox without angering my users?

Solution:

Try the following:

<TextBlock Text="{Binding Brokerage, StringFormat={}{0:#.##}" />

It will format to two decimal places and won’t show zeroes.

OR

Use the fixed-point numeric format string with two decimal places, F2:

<TextBlock Text="{Binding Brokerage, StringFormat={}{0:F2}}" />

WPF