Ticket Q550491
Visible to All Users

Create a numeric mask that allows inputting float values with a predefined number of decimals

created 11 years ago

Hello,

I am setting the Mask property of a repository item for float numbers as follows :
MaskType = Numeric
EditMask = ########0.#####

When I edit the value and type something the decimal separator ('.' or ',') automatically appears .
Is there a way to avoid this?

I just want to have a repository item that accepts any float number.
Is there any other way (ie without a mask) to prepare such an item? Having a mask is restrictive eg my mask above permits 5 decimal digits only.

Thank you

Yannis

Comments (2)
YM YM
Yannis Makarounis 11 years ago

    Somebody changed the subject line of my issue!
    Also the automated response I got does not seem to answer my question. Finally how can I get the attached sample project?
    I cannot find here Jannet's answer

    DevExpress Support Team 11 years ago

      Hi Yannis,
      Yes, I've changed the subject of this topic and I'm currently working to prepare a solution for you. Please give me additional time.

      Answers approved by DevExpress Support

      created 11 years ago (modified 11 years ago)

      Hello Yannis,
      Thank you for your patience.
      To accomplish this task, I suggest that you use the RegEx mask type instead of Numeric, and specify the Mask properties as follows:

      C#
      Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.RegEx; Mask.EditMask = @"\d{1,9}(\R.\d{0,5})?"; Mask.SaveLiteral = true; Mask.AutoComplete = DevExpress.XtraEditors.Mask.AutoCompleteType.None;

      The \d{1,9}(\R.\d{0,5})? mask string permits maximum nine digits, minimum one digit of the integer part and maximum five decimals.
      Please try the sample project in the attachment and let us know whether or not this approach is suitable for you.

        Comments (2)
        YM YM
        Yannis Makarounis 11 years ago

          Thank you Jannet
          I tried your solution but I have a problem.
          I setup repository item for a grid column as follows
                          RepositoryItemTextEdit ri = new RepositoryItemTextEdit();
                          ri.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.RegEx;
                          ri.Mask.EditMask = @"\d{1,9}(\R.\d{0,5})?";
                          ri.Mask.SaveLiteral = true;
                          ri.Mask.AutoComplete = DevExpress.XtraEditors.Mask.AutoCompleteType.None;
          When I go to edit mode the decimal point dissapears eg. 12.345 becomes 12345. This does not happen if the decimal point is '.' but it does happen if the decimal point is ','.
          I cannot reproduce it in your example.
          Yannis

          DevExpress Support Team 11 years ago

            Hello Yannis,
            This happens because the mask string is set up in order to display a character specified by the System.Globalization.NumberFormatInfo.NumberDecimalSeparator property of the current culture as a decimal separator. The default value for System.Globalization.NumberFormatInfo.InvariantInfo is ".".
            Yes, it is possible to specify several characters as a decimal separator (based on your requirements - a period (.) and comma(,)). For this, change the mask string as follows:

            C#
            ri.Mask.EditMask = @"\d{1,9}([\.\,]\d{0,5})?";

            In this mask string, any character, which matches a single character, included in the specified set of characters - [.,] with the preceding backslash, is considered as a decimal separator in the visual representation of the string.
            However, in this case an editor will return not a decimal value as an edit value, but a string value. If you need to operate decimal values, it is necessary to specify a single character as a decimal separator. You can customize the default number format. To perform this, use the approach is described in the Decimal point is comma on numeric keypad thread. Or, you can change the regional settings as it is described in the Number Formatting sub-article of the Globalization Step-by-Step article .
            Attached is a sample project demonstrating this functionality. Feel free to contact us if you have additional requirements.

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.