Mohammad Zare
Mohammad Zare

Reputation: 1509

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

Upvotes: 4

Views: 3503

Answers (1)

stukselbax
stukselbax

Reputation: 5935

StringFormat is what you need.

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

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

Upvotes: 8

Related Questions