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

RadNumericTextBox Format

3 Answers 407 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Leandro
Top achievements
Rank 1
Leandro asked on 06 Aug 2012, 01:44 PM
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?

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 07 Aug 2012, 02:00 PM
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
0
Leandro
Top achievements
Rank 1
answered on 07 Aug 2012, 06:14 PM
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
0
Vasil
Telerik team
answered on 09 Aug 2012, 02:23 PM
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.
Tags
General Discussions
Asked by
Leandro
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Leandro
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or