floating point number printf/string formating

This is a discussion on floating point number printf/string formating within the C++ Programming forums, part of the General Programming Boards category; I'm trying to format a certain string as shown in the snippet that I'm posting. Code: CString display; display.Format("%3.1f", 100*zshow); ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    222

    floating point number printf/string formating

    I'm trying to format a certain string as shown in the snippet that I'm posting.

    Code:
    CString display;
    display.Format("%3.1f", 100*zshow);
    For example, if 100*zshow is 3.5, I would like the string to show 03.5. Another case would be if 100*zshow is 10.2, it should show 10.2. However, this is not the case with 3.5, as it shows 3.5 rather than 03.5. I have also tried the flag "%03.1f", but it didn't work all that well either with respect to adding the extra zero when I don't have enough digits. What would be the easiest way to add the zero when needed?

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Perhaps you just need "%04.1" as the number of digits also seems to include the decimal point (printf and boost::format, CString is not a standard string, I'm afraid).
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    222
    CString is a MFC variable, specific to Microsoft projects only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. floating point number comparison
    By lehe in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2009, 08:11 PM
  2. floating point number comparison
    By stanlvw in forum C++ Programming
    Replies: 9
    Last Post: 04-27-2009, 02:44 PM
  3. how to read a digit of a floating point number?????
    By spicy_centipede in forum C Programming
    Replies: 15
    Last Post: 07-14-2007, 12:43 PM
  4. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-26-2001, 12:45 AM
  5. Replies: 2
    Last Post: 09-10-2001, 01:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21