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

Issues with percentages

2 Answers 58 Views
NumericUpDown
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 01 Nov 2010, 07:51 PM
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 Answers, 1 is accepted

Sort by
0
Boyan
Telerik team
answered on 03 Nov 2010, 05:02 PM
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
0
Jason
Top achievements
Rank 1
answered on 05 Nov 2010, 04:40 PM
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.
Tags
NumericUpDown
Asked by
Jason
Top achievements
Rank 1
Answers by
Boyan
Telerik team
Jason
Top achievements
Rank 1
Share this question
or