Thread: setting fixed floats in edit box

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    164

    setting fixed floats in edit box

    I'm trying to set the number that appears in an edit box to a fixed decimal point. I only want 2 place holders after a decimal point, instead of how many exist. I know how to do this using iomanip.h settings on console programs, but can anyone point me to the right direction using windows programing with edit boxes?

    below is some sample code of how I set up my code to udpate the edit boxes:
    Code:
    interest = monthlyinterest + originalprincipal;
    UpdateData (false);
    I want interest to only show 4.34 instead of 4.34444444444444
    Any Ideas?

    I set the properties of the edit box to number, but that does not do the trick....

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Instead using DDX_Text() on a float/double, use it on CString.
    Use CString.Format() to format the float/double value the way you want (ie. "%.2f").

    gg

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    164
    Thanks for the reply Codeplug,
    I assume DDX_Text() referrs to the statement UpdateData ()? At least according to my book in front of me... LOL!

    But I'm confused on using the CString.Format(). I don't have a reference in any of my books, do you have an example or suggestion for reference, similar to the UpdateData () for the DDX_Text();

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    CString::Format() uses a format specification field just like printf().
    The format specification field "%.2f" will format a float/double the way you want.

    gg

  5. #5
    Registered User
    Join Date
    May 2004
    Posts
    164
    Cool, I see what ya mean, I'll play around with that, I was concerned about using a conversion from double to string....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. WS_HSCROLL in ES_READONLY edit box error
    By Homunculus in forum Windows Programming
    Replies: 4
    Last Post: 02-13-2006, 08:46 AM
  3. Multiline Edit Box Parser
    By The Brain in forum Windows Programming
    Replies: 6
    Last Post: 11-01-2005, 07:15 PM
  4. display a file in dropdown edit box
    By sunburnbyRA in forum Windows Programming
    Replies: 2
    Last Post: 03-10-2004, 01:58 PM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM