Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. formatting output (CString .Format...)

formatting output (CString .Format...)

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Joan M
    wrote on last edited by
    #1

    Hello, INTRODUCTION: I need to show four real numbers in a CStatic. I've linked that CStatic to a CString var (let's call it statstring). QUESTION: I'm using this syntax:

    statstring.Format(" AB: %4.4lfmm - CD: %4.4lfmm - EF: %4.4lfmm - GH: %4.4lfmm",CAB,CCD,CEF,CGH);

    I'm trying to show something like: "AB: 0000.0000 - CD: 0000.0000 - EF: 0000.0000 - GH: 0000.0000" but I get: "AB: 0.0000 - CD: 0.0000 - EF: 0.0000 - GH: 0.0000" and the problem (is merely anaesthetic problem) is that each time that the numbers change they change their position too. How should I modify the format string in order to get it? As always thank you in advance.

    https://www.robotecnik.com freelance robots, PLC and CNC programmer.

    M K 2 Replies Last reply
    0
    • J Joan M

      Hello, INTRODUCTION: I need to show four real numbers in a CStatic. I've linked that CStatic to a CString var (let's call it statstring). QUESTION: I'm using this syntax:

      statstring.Format(" AB: %4.4lfmm - CD: %4.4lfmm - EF: %4.4lfmm - GH: %4.4lfmm",CAB,CCD,CEF,CGH);

      I'm trying to show something like: "AB: 0000.0000 - CD: 0000.0000 - EF: 0000.0000 - GH: 0000.0000" but I get: "AB: 0.0000 - CD: 0.0000 - EF: 0.0000 - GH: 0.0000" and the problem (is merely anaesthetic problem) is that each time that the numbers change they change their position too. How should I modify the format string in order to get it? As always thank you in advance.

      M Offline
      M Offline
      MVH
      wrote on last edited by
      #2

      From the top of my hat... Add some zeroes: statstring.Format(" AB: %04.4lfmm - CD: %04.4lfmm - EF: %04.4lfmm - GH: %04.4lfmm",CAB,CCD,CEF,CGH); I didn't try whether it works. ------------------------------------------ Experience is the name every one gives to their mistakes. -- Oscar Wilde Experience is one thing you can't get for nothing. -- Oscar Wilde

      J 1 Reply Last reply
      0
      • M MVH

        From the top of my hat... Add some zeroes: statstring.Format(" AB: %04.4lfmm - CD: %04.4lfmm - EF: %04.4lfmm - GH: %04.4lfmm",CAB,CCD,CEF,CGH); I didn't try whether it works. ------------------------------------------ Experience is the name every one gives to their mistakes. -- Oscar Wilde Experience is one thing you can't get for nothing. -- Oscar Wilde

        J Offline
        J Offline
        Joan M
        wrote on last edited by
        #3

        Hello, Thank you for your rapid answer, but it didn't worked...

        https://www.robotecnik.com freelance robots, PLC and CNC programmer.

        M 1 Reply Last reply
        0
        • J Joan M

          Hello, Thank you for your rapid answer, but it didn't worked...

          M Offline
          M Offline
          MVH
          wrote on last edited by
          #4

          Ok, try %09.4 That one works, I tested it. 0 is flag telling to fill the minimum length with zeroes, 9 is the length, 4 is the precision (in case someone wonders about that). ------------------------------------------ Experience is the name every one gives to their mistakes. -- Oscar Wilde Experience is one thing you can't get for nothing. -- Oscar Wilde

          J 1 Reply Last reply
          0
          • J Joan M

            Hello, INTRODUCTION: I need to show four real numbers in a CStatic. I've linked that CStatic to a CString var (let's call it statstring). QUESTION: I'm using this syntax:

            statstring.Format(" AB: %4.4lfmm - CD: %4.4lfmm - EF: %4.4lfmm - GH: %4.4lfmm",CAB,CCD,CEF,CGH);

            I'm trying to show something like: "AB: 0000.0000 - CD: 0000.0000 - EF: 0000.0000 - GH: 0000.0000" but I get: "AB: 0.0000 - CD: 0.0000 - EF: 0.0000 - GH: 0.0000" and the problem (is merely anaesthetic problem) is that each time that the numbers change they change their position too. How should I modify the format string in order to get it? As always thank you in advance.

            K Offline
            K Offline
            karl_w
            wrote on last edited by
            #5

            statstring.Format(" AB: %09.4lfmm - CD: %09.4lfmm - EF: %09.4lfmm - GH: %09.4lfmm",CAB,CCD,CEF,CGH); 0 indicates to fill up with zeros before the comma, 9 gives the minimal length of output (4 before the comma + comma + 4 after comma), 4 gives the numbers after the comma -- karl

            J 1 Reply Last reply
            0
            • M MVH

              Ok, try %09.4 That one works, I tested it. 0 is flag telling to fill the minimum length with zeroes, 9 is the length, 4 is the precision (in case someone wonders about that). ------------------------------------------ Experience is the name every one gives to their mistakes. -- Oscar Wilde Experience is one thing you can't get for nothing. -- Oscar Wilde

              J Offline
              J Offline
              Joan M
              wrote on last edited by
              #6

              Thank you! this is one of the stupid questions that are very easy but that their answers are hard to find in the MSDN. Once again thank you...

              https://www.robotecnik.com freelance robots, PLC and CNC programmer.

              1 Reply Last reply
              0
              • K karl_w

                statstring.Format(" AB: %09.4lfmm - CD: %09.4lfmm - EF: %09.4lfmm - GH: %09.4lfmm",CAB,CCD,CEF,CGH); 0 indicates to fill up with zeros before the comma, 9 gives the minimal length of output (4 before the comma + comma + 4 after comma), 4 gives the numbers after the comma -- karl

                J Offline
                J Offline
                Joan M
                wrote on last edited by
                #7

                Thank you! this is one of the stupid questions that are very easy but that their answers are hard to find in the MSDN. Once again thank you...

                https://www.robotecnik.com freelance robots, PLC and CNC programmer.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups