How to show numbers correctly in wpf data binding?

data-binding, floating-point, format, wpf, xaml

Solution

StringFormat is what you need.

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

If this is not work, try '{0:0.##}'

Problem

i am using wpf and my problem is in showing float numbers. in general when i bind my data(float number) to a datagrid column it even shows two zero after my rounded number (3.00) but i want to show this two zero just if my value is not rounded. how to solve this problem? 3 -> 3 not 3.00 3.62 -> 3.62

Original source