NumericUpDown allows to enter commas

6 posts, 1 answers
  1. Anton
    Anton avatar
    3 posts
    Member since:
    Dec 2012

    Posted 17 May 2013 Link to this post

    <telerik:RadNumericUpDown Value="{Binding DaysNumber}" Minimum="1" IsInteger="True" VerticalAlignment="Center" Margin="5" Maximum="999">
        <telerik:RadNumericUpDown.NumberFormatInfo>
            <globalization:NumberFormatInfo NumberGroupSeparator="" NumberDecimalSeparator="." />
        </telerik:RadNumericUpDown.NumberFormatInfo>
    </telerik:RadNumericUpDown>

    NumericUpDown control allows to enter commas (the screenshot is  attached). How can I forbid that?
  2. Anton
    Anton avatar
    3 posts
    Member since:
    Dec 2012

    Posted 17 May 2013 Link to this post

    I mean, how to do that properly without handling events. Now it looks like a defect in the control.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Answer
    Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 22 May 2013 Link to this post

    Hello Anton,

    Thank you for contacting us.

    By design in the RadNumericUpDown control when the controls IsInteger property is set to true the control allows the typing of separators but when the value is parsed via lost focus or enter keyboard key press the value is parsed correctly to integer. After investigating the issue however we found a bug that causes the NumberDecimalSeparator to not be used if the other (CurrencyDecimalSeparator, PercentDecimalSeparator) are not set to the same separator. We logged the issue in our Public Issue Tracker System where you can track its status. As a workaround for this issue all you need to do is set those properties in the NumberFormatInfo, also if you don't want the comma and dot symbols to be allowed you could simply set the separators to a symbol that is less likely to be pressed like the "™" symbol. The next code snippet shows the described approach:
    <telerik:RadNumericUpDown VerticalAlignment="Center" HorizontalAlignment="Center"
                                SmallChange="0.1" IsInteger="True"
                                Minimum="1"  Margin="5" Maximum="99999">
        <telerik:RadNumericUpDown.NumberFormatInfo>
            <globalization:NumberFormatInfo NumberDecimalSeparator="™" CurrencyDecimalSeparator="™" PercentDecimalSeparator="™"
                                            NumberGroupSeparator="" CurrencyGroupSeparator="" PercentGroupSeparator=""/>
        </telerik:RadNumericUpDown.NumberFormatInfo>
    </telerik:RadNumericUpDown>
    Hope this is helpful.

    I updated your Telerik points for bringing this to our attention, if you have any other questions feel free to write to us again.

    Regards,
    Vladi
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Anton
    Anton avatar
    3 posts
    Member since:
    Dec 2012

    Posted 18 Jun 2013 Link to this post

    Thank you, Vladi!
  6. Koen
    Koen avatar
    27 posts
    Member since:
    Apr 2012

    Posted 28 Jun 2013 Link to this post

    To make some sense out of this behavior:

    The RadNumericUpDown parses the text as follows:


    double.TryParse(text, NumberStyles.Any, formatInfo, out parsedValue);

    It uses "NumberStyles.Any", which inspects the formatInfo.

    Like Vladi mentioned, if your formatInfo does not contain information on "CurrencyDecimalSeparator" and "CurrencyGroupSeparator", CurrencyGroupSeparator will default to comma.
    That's why the parsing, and thus the control, will still accept commas.

    The issue is in the parsing using "NumberStyles.Any".
    It should take into account the "ValueFormat" property of the RadNumericUpDown, and use 
    "NumberStyles.Number", "NumberStyles.Currency" accordingly in the parsing.


    Regards,
    Koen
  7. Koen
    Koen avatar
    27 posts
    Member since:
    Apr 2012

    Posted 28 Jun 2013 Link to this post

    To make some sense out of this behavior:

    The RadNumericUpDown parses the text as follows:


    double.TryParse(text, NumberStyles.Any, formatInfo, out parsedValue);

    It uses "NumberStyles.Any", which inspects the formatInfo.

    Like Vladi mentioned, if your formatInfo does not contain information on "CurrencyDecimalSeparator" and "CurrencyGroupSeparator", CurrencyGroupSeparator will default to comma.
    That's why the parsing, and thus the control, will still accept commas.

    The issue is in the parsing using "NumberStyles.Any".
    It should take into account the "ValueFormat" property of the RadNumericUpDown, and use 
    "NumberStyles.Number", "NumberStyles.Currency" accordingly in the parsing.


    Regards,
    Koen
Back to Top
UI for WPF is Visual Studio 2017 Ready