Search code examples
c#wpfdata-binding

WPF - Binding decimal with StringFormat


I want to display a decimal with a Binding in a TextBlock.

The problem occurs when the decimal is 0. Nothing is displayed in the TextBox.

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

Solution

  • This should do the trick:

    {0:#,0.##}
    

    Note: As @ASh pointed out:
    Values between 0.0 and 1.0 will be displayed as 0.X instead of .X (e.g. 0.31 instead of .31)