Issues with percentages

3 posts, 0 answers
  1. Jason
    Jason avatar
    3 posts
    Member since:
    Sep 2010

    Posted 01 Nov 2010 Link to this post

    As I understand it, percentage handling in the NumericUpDown control is supposed to behave like Excel. Here is the behavior of a cell formatted as a percentage in Excel 2007 SP2:

    Enter in 1 - Excel displays 1.00%
    Enter in .01 - Excel displays 1.00%
    Enter in 500 - Excel displays 500.00%
    Enter in .5 - Excel displays 50.00%


    I'm using this XAML:

        <Grid x:Name="LayoutRoot" >
            <telerik:RadNumericUpDown x:Name="numericUpDown" />
        </Grid>

    With this C# code-behind:
            public CEBOSNumericUpDown()
            {
                InitializeComponent();
            }

            public ValueFormat NumericValueFormat
            {
                get
                {
                    return this.numericUpDown.ValueFormat;
                }

                set
                {
                    this.numericUpDown.ValueFormat = value;

                    if (value == ValueFormat.Percentage)
                    {
                        this.numericUpDown.SmallChange = .005;
                    }
                }
            }

    Being called  with ValueFormat=ValueFormat.Percentage and bound to a class property that is defined as a double.

    I get the following behavior:

    Enter in 1 - Get 100%
    Enter in 1.0 - Get 1000%
    Enter in 0.01 - Get 100%
    Enter in 500 - Get 50,000%
    Enter in .5 - Get 500%

    Note that, in order to clear the previous value, have to hit backspace to clear the control - typing while the control's contents are highlighted does not overwrite the contents as is standard on pretty much every other control. The control also does not display decimals at all, which is the behavior in Excel.

    How can I duplicate Excel's handling of percentages in this control, or is it possible at all?
  2. Boyan
    Admin
    Boyan avatar
    758 posts

    Posted 03 Nov 2010 Link to this post

    Hi Jason,

    Thank you for the detailed explanation. As far as I can see in your case the RadNumericUpDown is ignoring the decimal separator. Could you please try if in the culture set on your PC the default decimal separator is not coma. In this case you are still able to enter a dot but it is ignored and so it is translated as a whole number.
    Please try to set in the code behind:
    numeric.NumberFormatInfo.PercentageDecimalSeparator= ".";
    and check if it will work as in Excel. If this doesn't help could you please send me a sample project where I can reproduce the issue.

    Regards,
    Boyan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Jason
    Jason avatar
    3 posts
    Member since:
    Sep 2010

    Posted 05 Nov 2010 Link to this post

    That fixes the main problem, to get the control to work exactly like Excel you need to coerce the new value to a percentage if the user does not hit the decimal, or if the user hits the decimal and the value is greater than 1.0. Good enough for me :)

    Thanks for your help.
Back to Top