XValue contains many decimal pl...">

How to round double in XAML, WPF?

I have the following code in XAML:

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

XValue contains many decimal places (1952.230822830529)

I want it to contain only 2 decimal places, such as 1952.23, and I want to do this in XAML code.

I searched the Internet, but did not find a solution to my problem - is it possible to do this in XAML using the string format?

+4
source share
3 answers

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

Try one of the following:

<TextBox Text="{Binding XValue, StringFormat=N2}" />
<TextBox Text="{Binding XValue, StringFormat=#,#.00}" />
+12
source

XValue - ( string),

<TextBlock Text="{Binding XValue, StringFormat={}{0:N2}}"/>
+4

Create an XAML converter and call Math.Round () in its Convert () method. See MSDN

0
source

Source: https://habr.com/ru/post/1535020/


All Articles