NumericUpDown - ValueFormat as Pecentage

17 posts, 0 answers
  1. Rander Castro
    Rander Castro avatar
    1 posts
    Member since:
    Jan 2010

    Posted 15 Jan 2010 Link to this post

    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
  2. Hristo Borisov
    Admin
    Hristo Borisov avatar
    298 posts

    Posted 15 Jan 2010 Link to this post

    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.
  3. DevCraft banner
  4. Wolfgang Kaiser
    Wolfgang Kaiser avatar
    9 posts
    Member since:
    Dec 2009

    Posted 13 May 2010 Link to this post

    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.
  5. Boyan
    Admin
    Boyan avatar
    758 posts

    Posted 14 May 2010 Link to this post

    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.
  6. Wolfgang Kaiser
    Wolfgang Kaiser avatar
    9 posts
    Member since:
    Dec 2009

    Posted 14 May 2010 Link to this post

    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.
  7. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 20 May 2010 Link to this post

    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.
  8. George Fryberger
    George Fryberger avatar
    6 posts
    Member since:
    May 2009

    Posted 21 Jun 2011 Link to this post

    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?
  9. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 24 Jun 2011 Link to this post

    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
  10. qwer
    qwer avatar
    18 posts
    Member since:
    Oct 2010

    Posted 07 Jul 2011 Link to this post

    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.
  11. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 14 Jul 2011 Link to this post

    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!

  12. dgendreau
    dgendreau avatar
    1 posts
    Member since:
    Oct 2004

    Posted 19 Mar 2013 Link to this post

    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.

  13. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 22 Mar 2013 Link to this post

    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.

  14. Tom
    Tom avatar
    4 posts
    Member since:
    May 2016

    Posted 10 Aug in reply to Yana Link to this post

    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?

  15. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 11 Aug Link to this post

    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.
  16. Tom
    Tom avatar
    4 posts
    Member since:
    May 2016

    Posted 11 Aug in reply to Yana Link to this post

    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}" />
                             

  17. Tom
    Tom avatar
    4 posts
    Member since:
    May 2016

    Posted 11 Aug in reply to Tom Link to this post

    Sorry error in the above snippet it should be

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

Back to Top
DevCraft banner