Multiplying by 100 when percentage format is set

2 posts, 1 answers
  1. Elifbars
    Elifbars avatar
    4 posts
    Member since:
    May 2010

    Posted 30 Jul 2010 Link to this post

    I have numericUpDown in my project which valueFormat should be percentage
    Here is my xaml code:

    <telerik:RadNumericUpDown Grid.Row="1" Grid.Column="1" Name="VMDCR"
                                    Value="{Binding Path=Tier.VMDCR,ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
                                    IsEditable="True" AutoReverse="False" Minimum="0"
                       SmallChange="0.1" LargeChange="0.1" ValueFormat="Percentage" >

    So when window with numericUpDown appears it's value is 0.00%
    When i select all it's content and type here it's value becomes for example 34 , but after it loses focus the value is set to 3,400.00% but i expect that it would be 34.00%.
    So, please, could you explain how can i achieve this? Why does the value multiply by 100 and how to avoid this behaviour?
  2. Answer
    Valeri Hristov
    Valeri Hristov avatar
    2252 posts

    Posted 02 Aug 2010 Link to this post

    Hello Elifbars,

    RadNumericUpDown uses String.Format() to format its string depending on the current culture and number format. The behavior of String.Format() is to multiply the value by 100 when it formats using percentage number format. For example the result of:

    String.Format("{0:P}", 5d);

    will be "500.00 %" (the decimal separator depends on your culture settings).

    To workaround this behavior you could use ValueFormat="Numeric" and set CustomUnit="%" - this way the control will behave as with regular numbers, but will display "%" at the end.

    Sincerely yours,
    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
Back to Top