We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Constraining the NumberDecimalDigits property in DoubleTextBox

Excuse me if there is something I have missed in the documentation of this control, but I was wondering if there is a way of allowing the NumberDecimalDigits property in the DoubleTextBox (or PercentTextBox for that matter) to be unlimited. That is, I''d like to have no constraints on the number of decimal digits that can be entered. So a user could enter 2.22 or 2.2222 but have the control avoid displaying trailing zeros as in 2.2200 Thanks in advance.

2 Replies

AD Administrator Syncfusion Team August 4, 2004 08:09 PM

Hi Mark, You could derive from the DoubleTextBox class and override the ApplyFormatting method as shown below. This would prevent zeros from being padded to the DoubleValue and 2.22 would show up as 2.22 and not 2.2200 (even if the NumberDecimalDigits property is set to 4). However, the only way to have unlimited number of decimal digits is to specify a large value to the NumberDecimalDigits property. public class CustomDoubleTextBox : DoubleTextBox { public CustomDoubleTextBox () : base() { } protected override string ApplyFormatting(string rawValue) { string returnString; double dValue = 0; if(rawValue != null && rawValue != String.Empty) dValue = Convert.ToDouble(rawValue); returnString = dValue.ToString(); return returnString; } } The complete sample that illustrates this workaround is attached here. Please refer to it and let me know if this meets your requirements. Thanks for your interest in Syncfusion products. Regards, Guru Patwal Syncfusion,Inc.


BS Brian Smith January 19, 2006 11:23 AM

It seems to me that this doesn''t solve the problem. If I want to input the number "1.04", then I cannot because the 0 will continually get truncated due to the formatting. Has anyone solved this issue? Thanks, Brian >Hi Mark, > >You could derive from the DoubleTextBox class and override the ApplyFormatting method as shown below. This would prevent zeros from being padded to the DoubleValue and 2.22 would show up as 2.22 and not 2.2200 (even if the NumberDecimalDigits property is set to 4). However, the only way to have unlimited number of decimal digits is to specify a large value to the NumberDecimalDigits property. > >public class CustomDoubleTextBox : DoubleTextBox > { > > public CustomDoubleTextBox () : base() > { > > } > > protected override string ApplyFormatting(string rawValue) > { > string returnString; > double dValue = 0; > > if(rawValue != null && rawValue != String.Empty) > dValue = Convert.ToDouble(rawValue); > > returnString = dValue.ToString(); > > return returnString; > } > } > >The complete sample that illustrates this workaround is attached here. Please refer to it and let me know if this meets your requirements. Thanks for your interest in Syncfusion products. > >Regards, >Guru Patwal >Syncfusion,Inc. >

Loader.
Live Chat Icon For mobile
Up arrow icon