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. Managed C++/CLI
  4. C++/CLI: Formatting outputs (decimal places, hexadecimal, case notation)

C++/CLI: Formatting outputs (decimal places, hexadecimal, case notation)

Scheduled Pinned Locked Moved Managed C++/CLI
questionc++workspace
6 Posts 4 Posters 6 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
    J_E_D_I
    wrote on last edited by
    #1

    Hi, when I was programming in console mode if I needed to display only 2 decimal values of a variable (e.g. Variable1) I would write this simple code:

    cout << "Variable1 = " << setprecision (2) << fixed << Variable1 << endl;

    But now in C++/CLI environment how can I display this value inside a textbox showing only 2 decimal values? Can I add some attributes to the following code?

    textBox1->Text= Variable1.ToString();

    And what about if I wanted to display it in Hexadecimal and/or in Upper case notation? Many thanks in advance!

    L J 2 Replies Last reply
    0
    • J J_E_D_I

      Hi, when I was programming in console mode if I needed to display only 2 decimal values of a variable (e.g. Variable1) I would write this simple code:

      cout << "Variable1 = " << setprecision (2) << fixed << Variable1 << endl;

      But now in C++/CLI environment how can I display this value inside a textbox showing only 2 decimal values? Can I add some attributes to the following code?

      textBox1->Text= Variable1.ToString();

      And what about if I wanted to display it in Hexadecimal and/or in Upper case notation? Many thanks in advance!

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      so you decided to use some type's ToString() method but you did not consider reading up about it? :~

      Luc Pattyn [Forum Guidelines] [My Articles]


      Fixturized forever. :confused:


      J 1 Reply Last reply
      0
      • L Luc Pattyn

        so you decided to use some type's ToString() method but you did not consider reading up about it? :~

        Luc Pattyn [Forum Guidelines] [My Articles]


        Fixturized forever. :confused:


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

        Any advice please on where to find more info on this? Thanks

        R 1 Reply Last reply
        0
        • J J_E_D_I

          Any advice please on where to find more info on this? Thanks

          R Offline
          R Offline
          Rob Graham
          wrote on last edited by
          #4

          Object.ToString() has several overloads. some accept formatting instructions and culture specifications. You can get help on MSDN (and in visual studio help). You should consult the ToString(0 documentation for the particular type you are concerned with, as the base class virtual methods are often overridden. The help for Int32[^] is typical, and should shed light on your question. There are many links to additional details on formatting in the help article.

          1 Reply Last reply
          0
          • J J_E_D_I

            Hi, when I was programming in console mode if I needed to display only 2 decimal values of a variable (e.g. Variable1) I would write this simple code:

            cout << "Variable1 = " << setprecision (2) << fixed << Variable1 << endl;

            But now in C++/CLI environment how can I display this value inside a textbox showing only 2 decimal values? Can I add some attributes to the following code?

            textBox1->Text= Variable1.ToString();

            And what about if I wanted to display it in Hexadecimal and/or in Upper case notation? Many thanks in advance!

            J Offline
            J Offline
            J_E_D_I
            wrote on last edited by
            #5

            In reply to my question...

            textBox1->Text= Variable1.ToString("N0"); //shows value with 0 decimal places
            textBox1->Text= Variable1.ToString("N2"); //shows value with 2 decimal places
            textBox1->Text= Variable1.ToString("X"); //shows value in Hexadecimal notation (capital case)
            textBox1->Text= Variable1.ToString("x"); //shows value in Hexadecimal notation (normal case)

            Hope it helps somebody out there like me. I am really amazed there isn't a decent manual on these very basic things... It must all be there on MSDN but I find it the most impossible reference to consult.

            T 1 Reply Last reply
            0
            • J J_E_D_I

              In reply to my question...

              textBox1->Text= Variable1.ToString("N0"); //shows value with 0 decimal places
              textBox1->Text= Variable1.ToString("N2"); //shows value with 2 decimal places
              textBox1->Text= Variable1.ToString("X"); //shows value in Hexadecimal notation (capital case)
              textBox1->Text= Variable1.ToString("x"); //shows value in Hexadecimal notation (normal case)

              Hope it helps somebody out there like me. I am really amazed there isn't a decent manual on these very basic things... It must all be there on MSDN but I find it the most impossible reference to consult.

              T Offline
              T Offline
              TigerNinja_
              wrote on last edited by
              #6

              MSDN string formatting instructions are tricky to find. Pro tip: Don't use ms search engine, it's horrible. use google with site:msdn.....com helper. Google Query used: c# ToString format decimal site:msdn.microsoft.com First link I found: (Almost) http://msdn.microsoft.com/en-us/library/fzeeb5cd.aspx[^] Linked from first: (We have a winner): http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx[^]

              R.Bischoff

              Tengas un buen dia

              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