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

RadNumericTextbox incorrect decimal places

3 Answers 158 Views
Input
This is a migrated thread and some comments may be shown as answers.
Antony
Top achievements
Rank 1
Antony asked on 21 Apr 2009, 09:01 AM
Hi everyone,

I have a RadNumericTextbox on a page that is set to display 2 decimal places.
If I set the initial value in the Page_Load to be 16.67 and then increase this value using the up arrow the control behaves as expected.
If I decrement this value below the initial 16.67 then the number suddenly displays 15,670000000000001 (15 decimal places), if I increment the number back to 16.67 or greater the decimal places displayed returns to 2.
I have tracked this down to the "AllowRounding" property, if set to false this behaviour occurs, if set to True the control behaves as expected.
Why is this happening? I need to set AllowRounding = false and do not want these additional decimal places.

Here is a simple test page which displays the behaviour:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="ScriptManager1">
        </asp:ScriptManager>
        <telerik:RadNumericTextBox ID="txtNum" ButtonsPosition="Right" MinValue="0" MaxValue="100" Type="Number" runat="server" ShowSpinButtons="true"   >
            <NumberFormat AllowRounding="false" DecimalDigits="2" />
            <IncrementSettings Step ="1" />
        </telerik:RadNumericTextBox>   
    </form>
</body>
</html>


using

 

System;

 

using

 

Telerik.Web.UI;

 

public

 

partial class _Default : System.Web.UI.Page

 

{

 

protected void Page_Load(object sender, EventArgs e)

 

{

txtNum.Value=16.67;

}

}


3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Apr 2009, 09:36 AM
Hi Antony,

I tried your code and able to replicate the behavior. So I attached OnValueChanged event to RadNumericTextBox in order to reset the value to 2 decimal places. See the workaround which I tried. Hope this help you.

ASPX:
 
<telerik:RadNumericTextBox ID="txtNum" ButtonsPosition="Right" MinValue="0" MaxValue="100" Type="Number" runat="server" ShowSpinButtons="true"   > 
    <NumberFormat AllowRounding="false" DecimalDigits="2" /> 
    <IncrementSettings Step ="1" /> 
    <ClientEvents OnValueChanged="OnValueChanged" /> 
</telerik:RadNumericTextBox>  

JavaScript:
 
<script type="text/javascript"
function OnValueChanged(sender, args) 
    var input = sender;   
    var number = input.GetValue().toString();    
    if(number.length - number.indexOf('.') > 3 && number.indexOf('.') > 0)    
    {    
        number = number.substring(0, number.indexOf('.') + input._numberFormat.DecimalDigits + 1);    
        input.SetValue(number);    
    }    
 </script> 

Thanks,
Shinu.
0
Antony
Top achievements
Rank 1
answered on 21 Apr 2009, 09:54 AM

Thanks Shinu for your quick response.

 

Can Telerik please confirm that this is a bug and give me some indication as to when it will be fixed.

I am writing a brand new web application and if possible I would like to keep the "workarounds" to a minimum so I would prefer to wait for a bug fix if possible.

Many thanks

Antony,

 

 

0
Accepted
Daniel
Telerik team
answered on 21 Apr 2009, 01:14 PM
Hello Antony,

I confirm that we are aware of the aforementioned behavior - the issue is already added to our product backlog. I assure you that our developers will do their best to investigate the problem as soon as it is possible.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Input
Asked by
Antony
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Antony
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or