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

Exponential values

3 Answers 33 Views
MaskedEditBox
This is a migrated thread and some comments may be shown as answers.
Ueli
Top achievements
Rank 2
Ueli asked on 22 Feb 2014, 08:00 PM
Hi,

in a form, I Need to use a TextBox to enter values in the exponential form. In Radform's textboxes, there's no possibility to directly validate the Input or to Format it like ##.##e##. Is there a way to do this by radform or do I Need to write my own Input Validation and formatting?


3 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 26 Feb 2014, 03:14 PM
Hi Ueli,

Thank you for contacting us.

For this purpose you can use RadMaskedEditBox since its purpose is to provide such features. This is how you can configure it for your case:
this.MaskedEditBox.MaskType = MaskType.Standard;
this.MaskedEditBox.Mask = "##.##e##";

More information about RadMaskedEditBox can be found here.

I hope this helps.

Regards,
George
Telerik
0
Ueli
Top achievements
Rank 2
answered on 26 Feb 2014, 04:21 PM
Hi,

unfortunately this doesn't work. I use the TextBox to enter data but as well to edit data. So I get the value of this TextBox from the database. The datatype there is float which is converted to double in the entity model. So the value is written as 500000 in the db and should be displayed as 5.00E05. I solved it now to convert it to a string and then back to a double value using try catch expressions to avoid wrong Input.
0
Peter
Telerik team
answered on 03 Mar 2014, 04:18 PM
Hi Ueli,

Thank you for writing back and for the clarifications.

I would like to clarify that RadMaskedEditBox uses as value of type object and you should keep this approach with manually converting values from/to (with float.TryParse) database value.
Also, you can try to inherit our RadMaskedEditBox and expose a Value property of type float which internally perform this cast:
public class MyMaskEditBox : RadMaskedEditBox
{
    public MyMaskEditBox()
    {
        this.ThemeClassName = typeof(RadMaskedEditBox).FullName;
    }
 
    public float Value
    {
        get
        {
            float res = 0;
            if (float.TryParse(base.Value.ToString(), out res))
            {
                return res;
            }
            else
            {
                base.Value = //your current custom logic
            }
             
        }
        set
        {
            base.Value = value.ToString();//try catch
        }
    }    
}

I hope this helps.

Regards,
Peter
Telerik
Tags
MaskedEditBox
Asked by
Ueli
Top achievements
Rank 2
Answers by
George
Telerik team
Ueli
Top achievements
Rank 2
Peter
Telerik team
Share this question
or