Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame
CFloatEdit is a CEdit derived class providing support for editing currency values.. The user specifies the initial value, the number of decimals, the characters for the comma and for the decimal point. The implementation will keep a consistent format during the editing process.
The user types the input digits in the edit field. The value associated with the control is updated every time the contents is changed. The format is also adjusted to match the new value. New commas are added / removed automatically.
Typing "-" will toggle the sign. The user can type that anywhere in the control, the sign will be placed in the appropriate position.
Changing any property for the field will determine the immediate update of the displayed information. The implementation keeps the appropriate position for the editing cursor when possible.
Pressing the decimal point character will align the currently typed value to the decimal point and will move the cursor to the first position after the decimal point
When created, the control automatically takes the system settings regarding the decimal point and the thousands separator.
Inserting CFloatEdit controls into the project
Insert the ogx or CFloatEdit.h and CFloatEdit.cpp files into the project
To add a CFloatEdit control into a dialog, just subclass the control or attach with the Class Wizard a variable of this control type. In both situations, do not forget to insert the appropriate include directive at the beginning of the file.
It is mandatory to initialize every CFloatEdit control with the method SetValue in the dialog or view initialization routine.
Property Default Values
Number of decimal digits 2
Comma character ","
Decimal point character "."
Commas visible YES
Start value It's mandatory to be set by the user
CFloatEdit(); Default constructor
virtual ~CFloatEdit(); Destructor
double GetValue(void); Get the current value stored on the field. These value is evaluated after each change in the current field
void SetValue(double dblValue); Set the current value stored in the field
int GetDecimals( void ); Get the number of the digits after the decimal point
void SetDecimals( int nDecimals ); Set the number of the digits after the decimal point
void EnableCommas(BOOL bNewHasCommas); Enable / disable the visibility of the comma delimiters
void SetComma(char cNewComma); Set the comma character
char GetComma(void); Get the comma character
void SetDecimalPoint(char cNewDecimal); Set the decimal point character
char GetDecimalPoint(void); Get the decimal point character (default ".")
Important things to be mentioned
The code works on MS Visual C++ version 4.2 or newer
Every CFloatEdit control must be initialized at the beginning, with a SetValue statement (e.g., m_FloatEditPrice.SetValue(0.0); ).
The control value is stored in a double variable. User must take into account the internal precision capabilities
The decimal point character is set by default to "." and the comma character to ",". These characters can be changed, but setting the same value for both will determine unpredictable behavior
Download demo project - 18 KB
Download source - 6 KB
Date Last Updated: April 3, 1999