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.
Unfortunately, activation email could not send to your email. Please try again.

Constraining the NumberDecimalDigits property in DoubleTextBox

Thread ID:

Created:

Updated:

Platform:

Replies:

17248 Aug 4,2004 09:09 AM Jan 19,2006 11:23 AM Windows Forms 2
loading
Tags: Tools
Mark Atkinson
Asked On August 4, 2004 09:09 AM

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.

Administrator [Syncfusion]
Replied On 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.

Brian Smith
Replied On 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. >

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;