I feel stupid now, but I am unable to create simple format to my numbers. I am using DevExpress 22.2 controls for WPF. Inside a grid is column, in which is only numbers. Sometimes the numbers have decimal part, and sometimes there is none.
Examples:
96,00000
120,65000
23,12003
I need the round number to be displayed like this '96' and the real number like this '120,65' and '23,12003'.
My WPF code for column:
<dxg:GridColumn Header="Počet/Objem" FieldName="Volume" BestFitModeOnSourceChange="AllRows" BestFitMode="AllRows" AllowBestFit="True">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<dxe:TextEdit Name="PART_Editor"
HorizontalContentAlignment="Right" MaskType="Numeric"
DisplayFormatString="n"
ShowBorder="False"
dxe:NumericMaskOptions.AlwaysShowDecimalSeparator="False"/>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
This formating always return numbers with 2 digits after decimal point (comma in my culture).
My resuls: '96,00' '120,65' '23,12'
Please, can someone help me? Thank you.
Ok ... found answer just a minute after asking ... false alarm and sorry.
DisplayFormatString="#,0.######"
Related
I bind single properties to a TextBox without a specific StringFormat with the intension to show the value exactly like the user entered it.
<TextBox x:Name="TBSingleValue" Text="{Binding Path=SingleValue, ValidatesOnDataErrors=True}" />
The current automatic StringFormat creates the following result:
123456789 => 1.234568E+08
0.123456789 => 0.1234568
I need to display the values within -10e-9 and 10e9 without the scientific formating or automatic round.
With a StringFormat:
<TextBox x:Name="TBSingleValue" Text="{Binding Path=SingleValue, ValidatesOnDataErrors=True, StringFormat={}{0:F9}}" />
it parsed as expected but now I get every Decimal place, even when the value doesn't need one.
4 => 4.000000000
So here my Question:
Do you know what kind of StringFormat I should use to display every enteres Decimal place without showing unnessessary ones?
Best case would also a support of , and . as Decimal delimiter.
Edit:
I came up with a quite simple solution:
<TextBox x:Name="TBSingleValue" Text="{Binding Path=SingleValue, ValidatesOnDataErrors=True, StringFormat={}{0:0.###########}}" />
The custom StringFormat character # shows a digit only if one is present. The 0 at the beginning ensures that there is a 0 at the beginning even for numbers of 0.001.
This structure disables the scientific notation and gives the number with the required precision, without unnecessary 0 at the end.
Even -0.00000001 is displayed correct.
I am following the tutorial here. The example contains the line
<TextBlock Text="{Binding ElementName=wnd, Path=ActualWidth, StringFormat=Window width: {0:#,#.0}}" />
binding the window width to the textblock. If I remove "#,#", I notice I get the same result except there is no comma in the number if it's greater than 999. I see what it's doing. If I change it to
<TextBlock Text="{Binding ElementName=wnd, Path=ActualWidth, StringFormat=Window width: {0:##,#.0}}" />
I get the same thing. So my question is what does # mean exactly. Looked at MSDN and searched google but almost every example does not use any # signs.
# is a digit placeholder numeric format specifier in .NET that is replaced with the corresponding digit if one is present. Please refer to the docs for more information.
It has nothing to do with XAML really. You might as well use it programmatically when you for example call the ToString overload of a numeric type that accepts a format string.
I am having an issue with NumberTextBox. Below is the xaml code.
<cc:NumberTextBox
Margin="5,0,5,0"
HorizontalAlignment="Stretch"
IsEnabled="{Binding IsEditable}"
Style="{StaticResource TextBox_Default}"
TabIndex="25"
IsDecimalAllowed="True"
Text="{Binding ProductQuantity, ValidatesOnDataErrors=True, StringFormat={}{0:#.##}, UpdateSourceTrigger=PropertyChanged}" />
It should allow user to enter only 2 digits after the decimal. I tried to use StringFormat but it i snot working.
Example: 23.65567 it should allow user to enter only 23.65
Any suggestions to fix this issue.
Thanks in advance.
First of all, NumberTextBox is not a standard part of WPF. you should tag whatever library you are using for that element. then you will find more help here.
This link goes to a page where you can write your own NumberTextBox. As for digit limiting, just test for the "dot" and allow two more key-downs.
This link is an open source collection for numeric input control
I want to databind a grid column in WPF so that the value looks like this for negative numbers
(1,234.00)
I can do Binding="{Binding Path=ContractBTM.BasisAmount,StringFormat={}{0:0.00;(0.00)}}" but that does not give me the separator.
I can do StringFormat=N but the negative values use the minus sign.
I tried using the #,### syntax but it doesn't like the comma in my binding string.
OK
I ended up going with StringFormat={}{0:#,##0.00;(#,##0.00)} and ignoring the errors
<TextBlock Text="{Binding Path=ContractBTM.BasisAmount, StringFormat={}{0:0.00;(0,000.00)}}" />
I was wondering, how do I show a 24hr clock in a WPF datagrid? At the moment, the datagrid has set itself to 12 clock, using am & pm which is just plain confusing.
In the datagrid it has a simple column binding
...and I get the following
6/29/2010 10:46:42AM
6/29/2010 11:14:10PM
alt text http://picasaweb.google.com/lh/photo/NT6sM72khL10KZvoRPS9ww?feat=directlink
I'm not positive that I understand what you are asking, but I believe you just want to change the time format in your bound data?
That's fairly easy - use StringFormat. For example:
<TextBlock x:Name="txt12Hour" Text="{Binding StringFormat={}{0:hh:mm:ss tt}}" />
<TextBlock x:Name="txt24Hour" Text="{Binding StringFormat={}{0:HH:mm:ss}}" />
txt12Hour shows something like 05:17:27 PM
txt24Hour shows something like 17:17:27
Use any of the same formatting rules that you'd use in a ToString() call in code. This applies not only to dates, but numbers, currencies, etc.