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

RadTextbox Decimal Places

5 Answers 465 Views
Input
This is a migrated thread and some comments may be shown as answers.
Bernard Myers
Top achievements
Rank 1
Bernard Myers asked on 21 Jan 2010, 11:01 AM

I'm using trial Q2 2009 controls with a RadNumericTextBox input for salary and have several issues:-
 

 
<telerik:RadNumericTextBox runat="server" ID="dataEarnedAnnualIncome" Text='<%# Bind("EarnedAnnualIncome") %>' NumberFormat-DecimalDigits="0" NumberFormat-AllowRounding="true" Tooltip="" /> 

 

 

 

 

 

1. I don't want any decimal places, however, no matter what I do the control allows me to enter several decimal places. I need the control to stop me enetring decimal places or limit it to the correct number like a masked control - how can I do this?

I've tried adding a OnClientBlur javascript function to disable the decimal point from input, which would only cater for numbers with no decimal places, but this doesn't work as none of the RadNumericTextBox validation then happens and I can enter non numeric text in the box - can my script be changed to make this work?
 

 
//Function to stop decimal point being input  
        function StripDecimalPoint(sender, eventArgs) {  
            var c = eventArgs.get_keyCode();  
            if (c == 46) { eventArgs._cancel = true; }  
            return false;  
        } 

 

 


2. The rounding is calculated incorrectly as rounding depends on the number of significant decimal places not just the values of the numbers. With no decimal places 0.45 should be rounded down to 0, however it is being rounded up to 1?

3. If I cannot limit the number of decimals the user inputs then its preferable to truncate the input, however, when I change the AllowRounding to false the input is not truncated but left exactly as entered by the user. Obvioulsy I'd prefer to stop the user being able to enter extra decimals but if I can't how do I need to change my line to get truncating to work?

If these are known issue when do you anticipate fixing them?

Thanks

 

5 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 21 Jan 2010, 12:31 PM
Hi Bernard,

RadNumericTextBox does not prevent the user from entering a decimal separator. However, this can be easily achieved by using the keypress handler - see example below.

We have fixed the problem, which causes 0.45 to be rounded to 1 and changes will take effect in the next RadControls version.


<%@ Page Language="C#" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
<head runat="server">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>RadControls</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
 
<telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server">
    <NumberFormat DecimalDigits="0" AllowRounding="true" />
    <ClientEvents OnKeyPress="preventDecimalSeparator" />
</telerik:RadNumericTextBox>
 
<script type="text/javascript">
 
function preventDecimalSeparator(sender, args)
{
    if (args.get_keyCharacter() == sender.get_numberFormat().DecimalSeparator)
        args.set_cancel(true);
}
 
</script>
 
</form>
</body>
</html>


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.
0
Bernard Myers
Top achievements
Rank 1
answered on 21 Jan 2010, 02:03 PM
Hi Dimo,

Thanks for the quick response. That works great for integers but do you have any suggestions or code samples for limiting it to say x decimal places?

I still have the truncating issue. My control does the rounding when it AllowRounding is set to true but does nothing when set to false.

The documentation says it should truncate it - how can I get it to truncate?

Thanks


0
Dimo
Telerik team
answered on 22 Jan 2010, 01:11 PM
Hello Bernard,

Truncating with disabled rounding works in the latest official version, please consider upgrading.

There is no native way to prevent users from entering more than X decimal numbers. However, you can subscribe to the KeyPress client event and cancel it if a specific number of decimal places has been reached. Note that you will have to check what is the current carret position. For example

<telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server">
    <NumberFormat DecimalDigits="3" AllowRounding="true" />
    <ClientEvents OnKeyPress="preventMoreDecimalPlaces" />
</telerik:RadNumericTextBox>
  
<script type="text/javascript">
  
function preventMoreDecimalPlaces(sender, args)
{
    var separatorPos = sender._textBoxElement.value.indexOf(sender.get_numberFormat().DecimalSeparator);
    if (args.get_keyCharacter().match(/[0-9]/) &&
        separatorPos != -1 &&
        sender.get_caretPosition() > separatorPos + sender.get_numberFormat().DecimalDigits)
        {
            args.set_cancel(true);
        }
}
  
</script>



All the best,
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.
0
Bernard Myers
Top achievements
Rank 1
answered on 22 Jan 2010, 01:33 PM
Cheers Dimo - will do somethiong to disable the extra inputs.

Still think it is quite strange implementation allowing the user to enter additional characters and the control changing user input values with an unconfigurable rounding formula.

Bernard
0
Dimo
Telerik team
answered on 22 Jan 2010, 01:43 PM
Hi Bernard,

You can disable rounding, set DecimalDigits to a large number and handle rounding manually in the ValueChanging event.

Regards,
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.
Tags
Input
Asked by
Bernard Myers
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Bernard Myers
Top achievements
Rank 1
Share this question
or