I need a radnumerictextbox with variable decimal digits, same as described in following code sample of yours -
http://www.telerik.com/community/code-library/aspnet-ajax/input/radnumerictextbox-with-variable-decimal-digits-not-rounded.aspx
This code sample is no longer working with new version of radnumerictextbox. So please provide me the updated solution for this problem.
I am using version 2012.3.1127.40 of telerik dlls.
Please let me know if more information is required for this.
Thanks,
Shefali Gupta
7 Answers, 1 is accepted
This is the code I am using ---
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="DefaultCS" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="radi" %>
<!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"
>
<
radi:RadScriptManager
ID
=
"ScriptManagerControl"
runat
=
"server"
EnableScriptCombine
=
"true"
/>
<
script
type
=
"text/javascript"
>
// The provided solution works for AutoPostBack as well as for client-side NumericTextBox
//
// Note: you cannot use the regular OnBlur client-side event of the numeric textbox
// as it is fired too late (after the value is already rounded)
// basically the idea is to check whether the entered number contains more decimal digits than the number format expects
// and that would be rounded. If that is the case we increase the NumberFormat.DecimalDigits count on-the-fly.
window.onload = function()
{
var numericTextBox = <%= RadNumericTextBox2.ClientID %>;
var oldTextBoxBlurHandler = numericTextBox.TextBoxBlurHandler;
numericTextBox.TextBoxBlurHandler = function(e)
{
var currentValue = numericTextBox.GetTextBoxValue();
var decimalPartStart = currentValue.indexOf(numericTextBox.NumberFormat.DecimalSeparator);
if (decimalPartStart != -1)
{
var decimalPart = currentValue.substring(decimalPartStart + 1);
decimalPart = decimalPart.replace(/0+$/, "");
alert('Hi');
var decimalDigits = parseInt(decimalPart.length, 10);
if (decimalDigits >= defaultDecimalDigits)
{
numericTextBox.NumberFormat.DecimalDigits = decimalDigits;
}
else
{
numericTextBox.NumberFormat.DecimalDigits = defaultDecimalDigits;
}
}
else
{
numericTextBox.NumberFormat.DecimalDigits = defaultDecimalDigits;
}
oldTextBoxBlurHandler.call(this, e);
}
}
</
script
>
<
div
>
<
radi:RadNumericTextBox
ID
=
"RadNumericTextBox2"
runat
=
"server"
Type
=
"Number"
>
</
radi:RadNumericTextBox
>
</
div
>
</
form
>
</
body
>
</
html
>
You can use the following approach:
<
telerik:RadNumericTextBox
ID
=
"RadNumericTextBox2"
runat
=
"server"
>
<
NumberFormat
AllowRounding
=
"false"
KeepNotRoundedValue
=
"true"
/>
<
ClientEvents
OnValueChanged
=
"setDisplayValue"
OnLoad
=
"setDisplayValue"
/>
</
telerik:RadNumericTextBox
>
function
setDisplayValue(sender, args) {
sender.set_displayValue(sender.get_value());
}
Hope this helps. Please give it a try and let me know if it works for you.
Regards,
Eyup
Telerik
The solution you provided is working for me. Thanks a lot!!!
Regards,
Shefali
Thank you!
Matt
I'm afraid not. Basically, there is no point to have more than 16 decimal digits in the input because on the server it will be cast to double, which have limited precision. Nevertheless, you can use an alternative solution without javascript:
<
telerik:RadNumericTextBox
ID
=
"RadNumericTextBox1"
runat
=
"server"
>
<
NumberFormat
AllowRounding
=
"false"
KeepNotRoundedValue
=
"true"
DecimalDigits
=
"99"
/>
</
telerik:RadNumericTextBox
>
Hope this helps.
Regards,
Eyup
Telerik
Hello Allen,
Although the DecimalDigits property can be set to a higher number just because of its type, realistically it can only operate with up to 16 digits:
Rounding digits must be between 0 and 15, inclusive.
This is due to inner specifics of the control.
There is a resource you can check for a possible workaround:
https://www.telerik.com/support/code-library/radnumerictextbox-with-variable-decimal-digits-not-rounded
But frankly said, it is too custom and quite old now so any modifications over it are beyond our support scope.
Regards,
Eyup
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.