RadNumericTextBox: Remove "Unused" Decimals

3 posts, 1 answers
  1. kencox
    kencox avatar
    106 posts
    Member since:
    Oct 2002

    Posted 05 Jan 2010 Link to this post

    Okay, this is a strange one, but the boss is asking for it....

    He doesn't want to display decimals in a RadNumericTextBox if the decimal portion equals .00.

    For example, if the value is 123.44, the texbox should display

    123.44

    However, if the number is 123.00 then the textbox should display

    123

    Does that make any sense? Does anyone have any idea how this could be done without a TON of "if" coding?

    Ken
  2. Answer
    Dimo
    Admin
    Dimo avatar
    8486 posts

    Posted 06 Jan 2010 Link to this post

    Hello Ken,

    You can achieve the described behavior by setting  NumberFormat.AllowRounding  to "false". If you don't want to disable rounding, then you will have to use some custom Javascript. Subscribe to the ValueChanged and Blur client events. In the event handler, you can access the formatted value inside the textbox with sender._textBoxElement.value.

    <telerik:RadNumericTextBox ID="RNTB1" runat="server">
        <ClientEvents OnBlur="RemoveZeros" OnValueChanged="RemoveZeros" />
    </telerik:RadNumericTextBox>
     
    <script type="text/javascript">
     
    function RemoveZeros(sender, args)
    {
        var tbValue = sender._textBoxElement.value;
        if (tbValue.indexOf(".00") != -1)
            sender._textBoxElement.value = tbValue.substr(0, tbValue.indexOf(".00"));
    }
     
    </script>



    Greetings,
    Dimo
    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. kencox
    kencox avatar
    106 posts
    Member since:
    Oct 2002

    Posted 06 Jan 2010 Link to this post

    Perfect! Thanks Dimo!

    Ken
Back to Top