CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    7

    ??? Displaying dollar amount in edit box?

    Okay, I'm feeling pretty stupid because I can't seem to display a float variable as a dollar amount in a dialog's edit box. (10.00 reads as 10) I thought this would be a simple procedure, but I can't find any Visual C++ support for this, at least I haven't had luck with the online materials or books I've checked. I would appreciate any suggestions.

    "Try not. Do, or do not. There is no try." - Yoda

  2. #2
    Join Date
    Jun 1999
    Location
    Pakistan
    Posts
    77

    Re: ??? Displaying dollar amount in edit box?

    If you are using the string then try to concatenate it and then display other wise in double this seems difficult.


  3. #3
    Join Date
    May 1999
    Location
    Miami, Florida
    Posts
    242

    Re: ??? Displaying dollar amount in edit box?

    I have been down this road!

    There are a handful of classes on this site for formating numerical values as a dollar, that is, including the $ and making sure that their are 2 and only 2 decimal places. I have found that this classes suck. Each has it's own unique flaw.

    The easiest way to format a number as a dollar amount is to use

    GetDlgItemText(IDC_EDIT, m_edit);



    then do something like

    double value = atof(m_edit);
    char buf[256];
    sprintf(buf, "%.2f", value);
    SetDlgItemText(IDC_EDIT, buf);



    Typing %.2f forces it to be 2 decimal places. You could include the $ symbol but it tends to clutter the output - I like to just see numbers. You would want to put these commands in the OnChange or OnUpdate() functions.

    Please email me if you have any problems with this code.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured