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

NumericTextBoxSetting - Real numbers?

3 Answers 164 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 18 Aug 2011, 03:53 AM
How do I set a textbox that has been assigned to a NumericTextBoxSetting control to accept real numbers. ie: a number with any number of decimal places.

The
DecimalDigits
property allows the setting to be 0 up to 99. This is not what I need.  What if my user enters a number with 600 decimal places?

Here is my code.

TextBox tbFloat = new TextBox();
string fID = ID + "Value" + i2;
tbFloat.ID = fID;
tbFloat.Attributes.Add("name", fID);
tbFloat.Text = Value;
c2.Controls.Add(tbFloat);
  
Telerik.Web.UI.NumericTextBoxSetting radF = new Telerik.Web.UI.NumericTextBoxSetting();
radF.EmptyMessage = "";
//radF.DecimalDigits = ? ;

radF.Type = Telerik.Web.UI.NumericType.Number;
radF.Validation.IsRequired = false;
  
TargetInput fi = new TargetInput();
fi.ControlID = fID;
radF.TargetControls.Add(fi);
  
RadInputManager1.InputSettings.Add(radF);

In the code above I have commented out the DecimalDigits line. Running this I get a textbox that accepts real numbers just fine, but always round them down to 2 decimal places! Huh?

I need one that accepts numbers of any number of decimal places.

I even tried this...

radF.DecimalDigits = -1 ;

But that of course does not work (would have been nice if it did) :)

Any clues on this one please?

Thanks

Brad









3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Aug 2011, 05:43 AM
Hello Brad,

Try setting AllowRounding to False and then set DecimalDigits to a large number thus you can handle rounding manually.
C#:
Telerik.Web.UI.NumericTextBoxSetting radF = new Telerik.Web.UI.NumericTextBoxSetting();
radF.EmptyMessage = "";
radF.DecimalDigits = 600 ;
radF.NumberFormat.AllowRounding = false;

Thanks,
Shinu.
0
Brad
Top achievements
Rank 1
answered on 18 Aug 2011, 06:07 AM
Shinu

That is not possible

According to this page

http://www.telerik.com/help/aspnet-ajax/p_telerik_web_ui_numerictextboxsetting_decimaldigits.html

.DecimalDigits cannot be set to a number greater than 99.

I used 600 as an example. The fact of the matter is I don't want any limit on how many decimal places they enter. This text box is part of a system were an admin of the site can created their own questions and specify the 'type' of answer they are expecting. If they specify the question requires a real floating point number, I don't want it rounded to 2 places OR be limited to some 99 point precision limit.

For example

Question 1:- Enter pi to 150 places.

Can't do that with the NumericTextBoxSettings

Brad
0
Vasil
Telerik team
answered on 23 Aug 2011, 10:52 AM
Hi Brad,

NumericTextBoxSettingis not designed to work with more than 99 decimal digits. You will have to use a regular TextBox and restrict only numbers to be entered. You could search the web for some solutions like this one.
Keep in mind that in the code-behind you will need to parse the string manually since it can't be casted to double or decimal because they don't provide such a precision.

Best wishes,
Vasil
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
General Discussions
Asked by
Brad
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Brad
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or