Search code examples
c#wpfdata-bindingwpfdatagrid

Number format for wpf datagridcell


i have a wpf datagrid control with 4 colums. All these 4 columns are binded with 4 properties of decimal type. So it appears in the grid cell like "43.00000", "456.000000", etc. How can it truncated to 43.00 ? I want all these decimal values to display in the grid cell as 43.00 and NOT 43.0000000. We cannot try the method .ToString("00.00", Culture....) since the datacolumns are binded with the 4 properties of a class in the XAML. I need only 2 digits after the point.

In the database, the datatype of these fields are defined as decimal (18,3).


Solution

  • Try

    Text="{Binding Test, StringFormat={}{0:0.00}}"
    

    it will have the same effect as .ToString("0:0.00")