This is a migrated thread and some comments may be shown as answers.

[Solved] MaskedEditorSettings Converts Decimal to Incorrect Value

6 Answers 114 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mihir Darji
Top achievements
Rank 1
Mihir Darji asked on 20 Jul 2009, 07:17 AM
Hi,

Using GridView to dynamically display the data and edit base don the data type.

Here is the code for my currency data type.

Case "Currency"
                                    editor = New MaskedTextBoxEditorSettings()
                                    editor.MaskType = MaskType.Numeric
                                    editor.Mask = "n1"
                                   
                                    fieldInstance.EditorSettings = editor
                                    fieldInstance.DataType = GetType(Decimal)
                                    fieldInstance.TextAlignment = TextAlignment.Right
                                    fieldInstance.DataFormatString = "{}{0:0.0}"

But when I put data as 0.3 in editor the value shown in Cell after losing focus is 0.300000011920929

Can you tell me what the problem is?



6 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 20 Jul 2009, 03:02 PM
Hi Mihir Darji,

Your code sets the format only for the editor. When the cell is not in edit mode , the editor is hidden and you will see the 'raw' value.
In order to fix it , you will need to set the DataFormatString property of the corresponding column as well. This will ensure data to be correctly formatted when the cell is not in edit mode.

Kind regards,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Mihir Darji
Top achievements
Rank 1
answered on 21 Jul 2009, 06:35 AM
Hi Pavel,

As you can see in my code I have already assigned the DataFormatString for the corresponding column.

fieldInstance.DataFormatString = "{}{0:0.0}"

The main thing is when it is coming from intial binding the data is shown as "4.4000" for a value of "4.4" , the same is converted to "4.4" when in edit mode, but as soon as Edit mode is ended the value shown in cell is "4.40003919..."

Let me know if I have missed something.

Mihir
0
Accepted
Pavel Pavlov
Telerik team
answered on 24 Jul 2009, 12:54 PM
Hello Mihir Darji,

Could you please try to use "{0:0.0}" instead of "{}{0:0.0}" when setting the DataFormatString from code behind. (e.g. remove the leading {})

The syntax you have used is suitable when setting it form XAML.

Greetings,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Mihir Darji
Top achievements
Rank 1
answered on 27 Jul 2009, 09:19 AM
Hi,

Thanks, It worked.

Mihir
0
mjaisi p
Top achievements
Rank 1
answered on 31 Aug 2009, 05:46 AM
hi

I used dataformatstring = "{}{0:0.0} im xaml, this is not formatting the data.
could any one help

Thanx
mjaisi
0
Pavel Pavlov
Telerik team
answered on 01 Sep 2009, 04:03 PM
Hello mjaisi p,

Typically such syntax in XAML should work . Please paste me your XAML as well as the type of the underlying data. I  will try to find out what the problem is.

Regards,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Mihir Darji
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Mihir Darji
Top achievements
Rank 1
mjaisi p
Top achievements
Rank 1
Share this question
or