Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to round double in XAML, WPF? [duplicate]

I have the following code in XAML:

<TextBlock Text="{Binding XValue}" />

The XValue contains a lot of decimals(1952.230822830529)

I want it to contain only 2 decimals like 1952.23 and i want to do this in the XAML code.

I have searched the internet but not found a solution to my problem - so is it even to do this in XAML using string format?

like image 229
Diemauerdk Avatar asked Apr 04 '14 12:04

Diemauerdk


1 Answers

This is a duplicate of this post (also the top result on google): How to format number of decimal places in wpf using style/template?

Try one of these:

<TextBox Text="{Binding XValue, StringFormat=N2}" />
<TextBox Text="{Binding XValue, StringFormat=#,#.00}" />
like image 193
alan Avatar answered Sep 22 '22 19:09

alan