Exponential values

4 posts, 0 answers
  1. Ueli
    Ueli avatar
    5 posts
    Member since:
    Dec 2013

    Posted 22 Feb 2014 Link to this post

    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?


  2. George
    Admin
    George avatar
    500 posts

    Posted 26 Feb 2014 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ueli
    Ueli avatar
    5 posts
    Member since:
    Dec 2013

    Posted 26 Feb 2014 Link to this post

    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.
  5. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 03 Mar 2014 Link to this post

    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
Back to Top