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

NumericUpDown - ValueFormat as Pecentage

15 Answers 614 Views
NumericUpDown
This is a migrated thread and some comments may be shown as answers.
Rander Castro
Top achievements
Rank 1
Rander Castro asked on 15 Jan 2010, 11:05 AM
Hi,

I have trouble when trying use the NumericUpDown control with the following 
configuration:

ValueFormat = ValueFormat.Percentage;
PercentiDecimalDigits = 4;

Scenario: If I set the value 0.4  for this control, after press TAB key to exit the control, when the control lost focus, it show 4.0000 %, but I need the control shows then value that I entered, it means, 0.4000 %.

How could I fix this, please?

Thanks

15 Answers, 1 is accepted

Sort by
0
Hristo Borisov
Telerik team
answered on 15 Jan 2010, 01:06 PM
Hi Rander Castro,

This is expected behavior since NumericUpDown internally uses formatting with the IFormatProvider provided by the NumberFormatInfo in which formatting value of 1 is formatted as 100%. You can easily just set the ValueFormat to Numeric and set the CustomUnit to % symbol.

Thank you for contacting us, and we look forward to answering your questions again.

Sincerely yours,
Hristo Borisov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Wolfgang Kaiser
Top achievements
Rank 1
answered on 13 May 2010, 11:10 PM
Hi Hristo ,

 This can't be expected behavior - definately not expected by an enduser.  I can't find the
RadNumericUpDown control useful at all as a percentage entry utiltiy.  In order for percentage entry to work I would expect that I can 1) limit validation from 0 to 100 can be enforced - which I can't get to work and 2) if I use the numeric scroller and change my percentage from 51% to 52% and then I click on the input area to type in a percentage amount the amount will change to 0.52
 if you look at the telerik sample code the percentage input doesn't work there either - well it works but not in a useful fashion.

 I used the following to get my percentage input to work:
<telerikInput:RadNumericUpDown x:Name="numPercent"   
SmallChange="1" LargeChange="1"   
Maximum="100" Minimum="0"   
Width="100" Height="25" IsEditable="True"   
ValueFormat="Numeric" CustomUnit="%" /> 
                 

and then i use a value converter on the binding to convert the 40% into 0.40:
numPercent.SetBinding(RadNumericUpDown.ValueProperty, new Binding()  
            {  
                Converter = new PercentageConverter(),  
                Source = txtpercentSet,  
                Mode = BindingMode.TwoWay,  
                Path = new PropertyPath("Text")  
            });  
 
// and here is the value converter (test only)  
 
private class PercentageConverter : IValueConverter  
        {  
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)  
            {  
                if (value.ToString() == string.Empty) return 0;  
                double v = System.Convert.ToDouble(value) * 100;  
                return v;  
            }  
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)  
            {  
                double v = (double)value / 100;  
                return v;  
            }  
        } 

Needless to say it would be nicer to have a COTS RadNumeric control that would work with percentages.
0
Boyan
Telerik team
answered on 14 May 2010, 08:44 AM
Hello Wolfgang Kaiser,

I think you can achieve the desired behavior with the RadNumericUpDown  ValueFormat=Percentage. In order to limit the percentages from 0 to 100 you must set Minimum =0 and  Maximum=1. And you need to set the SmallChange to 0.01 in order for the arrows to change 1 percent down/up. I think this tweak should work fine for you. 

All the best,
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
Wolfgang Kaiser
Top achievements
Rank 1
answered on 14 May 2010, 09:31 AM
You are correct that works using the scroller, but as soon as you click inside the input field to perform manual input the value of 42% (for example) changes to 0.42.  That's not acceptable for users of our application.
0
Valeri Hristov
Telerik team
answered on 20 May 2010, 08:14 AM
Hi Wolfgang,

The behavior comes from the fact that the Value of the control is displayed without formatting when the control has the focus, but when it loses the focus, the Value is formatted as percentage. String.Format("{0:P}", 1.5) will return "150%", hence the behavior of RadNumericUpDown. I admit that this is strange and we should think of a way to change it in the future, however there is another problem - if someone is used to the current behavior and all of his data is stored as the current control expects, his application will be broken.

Regards,
Valeri Hristov
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
George Fryberger
Top achievements
Rank 1
answered on 21 Jun 2011, 03:34 PM
I agree with Wolfgang.  This is how I expected the control to work and was disappointed that it didn't.  With this information I can get it to do what I need it to but it would be nice if we could configure the control to behave like this.  Are there any plans to change this behavoir?
0
Konstantina
Telerik team
answered on 24 Jun 2011, 09:12 AM
Hello Kevin,

For now, we don't have any plans for changing the behaviour of the NumericUpDown control. However, if we receive some more clients' requests we will consider implementing it in one of our future releases.

Please let us know if you have any other concerns about our controls.

Kind regards,
Konstantina
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
qwer
Top achievements
Rank 1
answered on 08 Jul 2011, 02:46 AM
I also agree with Wolfgang and Kevin,

Our application facing same complains from end user experiences.

From end user perspective , for 10 % they want to key in as 10 not 0.1.

Up and Down strollers are fine and they pretty happy but when click into control, awful complains start.

So, I strongly request Telerik team to consider/support about that feature in future release and that will be great.
0
Yana
Telerik team
answered on 14 Jul 2011, 08:07 AM
Hello Qwer,

Thank you for sending your feedback, it will be considered.

Regards,
Yana
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
dgendreau
Top achievements
Rank 1
answered on 19 Mar 2013, 03:37 PM
Let me also add support to change that default behavior for the NumericUpDown control. It is unacceptable behavior that the format of the control changes depending if the control has focus or not. If the format is in percentage it should be editable as a percentage also. Otherwise this is just confusing.

0
Yana
Telerik team
answered on 22 Mar 2013, 12:55 PM
Hello David,

Thank you for writing to us.

All the best,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Tom
Top achievements
Rank 1
answered on 10 Aug 2016, 02:10 PM

This is totally farcical!

It is currently impossible to have a numeric up down control that shows 0 - 100 range that users understand but internally translates that to a double value between 0-1?

Have I got this right, because I have now spent 2 hours smashing my head against the keyboard trying to achieve this most basic UI functionality, enter a Percentage! 

Anybody figured this out?

0
Yana
Telerik team
answered on 11 Aug 2016, 09:30 AM
Hello Tom,

Indeed, when RadNumericUpDown has its format set to Percentage, it translates the value to double, however, when editing the value it is shown as a double as well.  We understand this is confusing and we have researched various approaches for changing the current behavior, however it is not possible without introducing a breaking change in the control.

As a work-around you could use CustomUnit property set to "%" instead of Percentage format and add a converter to convert the value to double. I have attached a simple project to demonstrate the approach, please download it and give it a try.

I hope this is an acceptable solution for you.

Regards,
Yana
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Tom
Top achievements
Rank 1
answered on 11 Aug 2016, 03:15 PM

As I posted to you in the trouble ticket you do not need to introduce a breaking change you could easily add another CustomUnit to support this (the most standard use-case). At the very least document this bug you won't fix.

Further more RadMaskedNumericInput  works perfectly, so we have 2 different controls with 2 different patterns, one broken and confusing, one working as expected.

Use this instead

<telerik:RadMaskedNumericInput FormatString="P" Mask=P Value="{Binding PercentageValue, Mode=TwoWay}" />
                         

0
Tom
Top achievements
Rank 1
answered on 11 Aug 2016, 03:17 PM

Sorry error in the above snippet it should be

<telerik:RadMaskedNumericInput FormatString="P" Mask="" Value="{Binding PercentageValue, Mode=TwoWay}" />

Tags
NumericUpDown
Asked by
Rander Castro
Top achievements
Rank 1
Answers by
Hristo Borisov
Telerik team
Wolfgang Kaiser
Top achievements
Rank 1
Boyan
Telerik team
Valeri Hristov
Telerik team
George Fryberger
Top achievements
Rank 1
Konstantina
Telerik team
qwer
Top achievements
Rank 1
Yana
Telerik team
dgendreau
Top achievements
Rank 1
Tom
Top achievements
Rank 1
Share this question
or