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 in control box

formatting output in control box

Scheduled Pinned Locked Moved C / C++ / MFC
c++announcement
3 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.
  • E Offline
    E Offline
    emrosa
    wrote on last edited by
    #1

    Hi...I'm developing a graphical interface. The programs computes some values that are later shown in control boxes in the screen. The program does already that, but I was wondering if there is any way to format that output. That is if the program is displaying in a control box a numeric variable it shows 99.9999 and not 99.999999 (or whatever). I'm using MFC to do most of the stuff, like showing and reading, and all the computations are mine. In the part where the values are shown, I'm calling UPDATE() with false, so to not read values, just show the values. Thanks, Eric Manuel Rosales Pena Alfaro PhD student Unversity of Essex Wivenhoe Park Colchester, CO4 3SQ Essex, Uk email: emrosa@essex.ac.uk tel: +44-01206-87311

    H J 2 Replies Last reply
    0
    • E emrosa

      Hi...I'm developing a graphical interface. The programs computes some values that are later shown in control boxes in the screen. The program does already that, but I was wondering if there is any way to format that output. That is if the program is displaying in a control box a numeric variable it shows 99.9999 and not 99.999999 (or whatever). I'm using MFC to do most of the stuff, like showing and reading, and all the computations are mine. In the part where the values are shown, I'm calling UPDATE() with false, so to not read values, just show the values. Thanks, Eric Manuel Rosales Pena Alfaro PhD student Unversity of Essex Wivenhoe Park Colchester, CO4 3SQ Essex, Uk email: emrosa@essex.ac.uk tel: +44-01206-87311

      H Offline
      H Offline
      HENDRIK R
      wrote on last edited by
      #2

      Formatin output can be easily done when using CString::Format or sprintf. When searching MSDN for the latter one, you'll find appropriate documentation on how to set the precision of your output.

      1 Reply Last reply
      0
      • E emrosa

        Hi...I'm developing a graphical interface. The programs computes some values that are later shown in control boxes in the screen. The program does already that, but I was wondering if there is any way to format that output. That is if the program is displaying in a control box a numeric variable it shows 99.9999 and not 99.999999 (or whatever). I'm using MFC to do most of the stuff, like showing and reading, and all the computations are mine. In the part where the values are shown, I'm calling UPDATE() with false, so to not read values, just show the values. Thanks, Eric Manuel Rosales Pena Alfaro PhD student Unversity of Essex Wivenhoe Park Colchester, CO4 3SQ Essex, Uk email: emrosa@essex.ac.uk tel: +44-01206-87311

        J Offline
        J Offline
        jhwurmbach
        wrote on last edited by
        #3

        You can use

        std::stringstream ss;
        ss << std::setprecision(4) << YourVariable
        m_Editbox.SetWindowText( ss.str().c_str() );

        You can look up the other modifiers beside std::setprecision() in the Help. There is one for any need. Or you simply use the old-fashioned way, from the days before C++ : sprintf() or its wrapper in the CString class, Format().


        My opinions may have changed, but not the fact that I am right.

        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