CFloatEdit - edit control for currency numbers




  • 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.
  • Editing features

  • 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
  • Method Prototypes

    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


    • There are no comments yet. Be the first to comment!

    Leave a Comment
    • Your email address will not be published. All fields are required.

    Top White Papers and Webcasts

    • IDC estimates that more than 70% of organizations have a cloud-first application deployment strategy to align with digital transformation initiatives. As such, many organizations are transitioning to Microsoft Office 365 and utilizing public clouds such as Microsoft Azure. However, IT leaders are discovering that default data protection schemes are not as robust as they desire. As a result, many are turning to Veeam® to provide the necessary data management and protection policies demanded by the …

    • How does this impact your content strategy? Content management markets are changing rapidly. Due to increased expectations of users, changes in IT and the need for organizations to rethink their digital strategy, Gartner has launched new Magic Quadrants (MQs) for Content Services Platforms (CSP) and Content Collaboration Platforms (CCP). These MQs have updated the definition of previous Enterprise Content Management (ECM) and Enterprise File Sync and Share (EFSS) markets respectively, and are tightly connected …

    Most Popular Programming Stories

    More for Developers

    RSS Feeds

    Thanks for your registration, follow us on our social networks to keep up-to-date