RadNumericTextBox Format

4 posts, 0 answers
  1. Leandro
    Leandro avatar
    20 posts
    Member since:
    Mar 2012

    Posted 06 Aug 2012 Link to this post

    Hi,

    I'm having problem with the format in the textbox.
    Today it looks like: 

    <telerik:RadNumerictextBox ID="txtValor" runat="server" MinValue="0">
        <NumberFormat AllowRounding="true" DecimalDigits="2">
    </telerik:RadNumerictextBox>

    When I fill with the value "50,45" for example, text and value properties are as follows:
    Text: 50,45
    Value: 50.450000000000003
    I do not understand, if I defined only two decimal places, why the 14 digits? this is a bug?
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 07 Aug 2012 Link to this post

    Hello,

    I am not able to reproduce this issue.

    Client side.


    Server side.



    My code.
    <telerik:RadNumericTextBox ID="txtValor" runat="server" MinValue="0">
              <NumberFormat AllowRounding="true" DecimalDigits="2" />
          </telerik:RadNumericTextBox>
          <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return ClientClick();"
              OnClick="Button1_Click" />
    protected void Button1_Click(object sender, EventArgs e)
      {
     
      }
    <script type="text/javascript">
              function ClientClick() {
                  var txtValor = $find("<%= txtValor.ClientID %>");
                  debugger;
                  return true;
              }
          </script>


    Thanks,
    Jayesh Goyani
  3. Leandro
    Leandro avatar
    20 posts
    Member since:
    Mar 2012

    Posted 07 Aug 2012 Link to this post

    Good afternoon,

    I've been doing some more tests and actually, this bug does not happen all the values ​​...
    follows the code used in the attached form and print the values​​.

    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication3.WebForm1" %>
     
    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
        <script type="text/javascript">
            function ClientClick() {
                var txtValor = $find("<%= RadNumericTextBox1.ClientID %>");
                debugger;
                return true;
            }
        </script>   
        </telerik:RadScriptBlock>     
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <div>
         
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" OnClientClick="return ClientClick();" />
            <telerik:RadNumericTextBox ID="RadNumericTextBox1" Runat="server" MinValue="0">
                <NumberFormat AllowRounding="true" DecimalDigits="2" />
            </telerik:RadNumericTextBox>
         
        </div>
        </form>
    </body>
    </html>
    Public Class WebForm1
        Inherits System.Web.UI.Page
     
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     
        End Sub
     
        Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
     
        End Sub
    End Class
  4. Vasil
    Admin
    Vasil avatar
    1635 posts

    Posted 09 Aug 2012 Link to this post

    Hello Leandro,

    NumberFormat settings are settings that are making difference only client side. When formatting the value that the client sees and before submitting it.

    Then it is converted to string and submitted to server. This string is accessible by the "Text "property of the numeric text box. And the Value property getter is basically these lines:

    if (String.IsNullOrEmpty(Text))
    {
        return null;
    }
    else
    {
        return double.Parse(Text, NumberFormatInfo.InvariantInfo);
    }

    So if the Text is correct and the Value is not, this is coming from the double precision and the double.Parse function.

    It is not a bug into the control. It is just the way that numbers are presented in double.

    You can parse the Text to Deciaml, that should not have this problem.

    Regards,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top