Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show numbers correctly in wpf data binding?

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

like image 338
Mohammad Zare Avatar asked Sep 03 '25 09:09

Mohammad Zare


1 Answers

StringFormat is what you need.

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

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

like image 89
stukselbax Avatar answered Sep 05 '25 00:09

stukselbax