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. type conversions

type conversions

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
7 Posts 7 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.
  • A Offline
    A Offline
    arr cpp
    wrote on last edited by
    #1

    how to convert from numeric types (such as double, int, long,...) to char[]? (i want to show the number in a window, so i need to convert it to char)

    L W N H T 6 Replies Last reply
    0
    • A arr cpp

      how to convert from numeric types (such as double, int, long,...) to char[]? (i want to show the number in a window, so i need to convert it to char)

      L Offline
      L Offline
      Lord Kixdemp
      wrote on last edited by
      #2

      http://www.cplusplus.com/ref/cstdlib/[^] ;-) Lord Kixdemp www.SulfurMidis.com www.SulfurSoft.tk [ftp://][http://][hotline://]tsfc.ath.cx

      1 Reply Last reply
      0
      • A arr cpp

        how to convert from numeric types (such as double, int, long,...) to char[]? (i want to show the number in a window, so i need to convert it to char)

        W Offline
        W Offline
        Waldermort
        wrote on last edited by
        #3

        Try using some of the numeric conversion functions, for example itoa(), ltoa().

        1 Reply Last reply
        0
        • A arr cpp

          how to convert from numeric types (such as double, int, long,...) to char[]? (i want to show the number in a window, so i need to convert it to char)

          N Offline
          N Offline
          normanS
          wrote on last edited by
          #4

          Or you could use the sprintf() function. That's good for getting secific formatting.

          1 Reply Last reply
          0
          • A arr cpp

            how to convert from numeric types (such as double, int, long,...) to char[]? (i want to show the number in a window, so i need to convert it to char)

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #5

            Hi arr2arr1arr, maybe it is some helpful to you http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_data_conversion.asp[^]

            1 Reply Last reply
            0
            • A arr cpp

              how to convert from numeric types (such as double, int, long,...) to char[]? (i want to show the number in a window, so i need to convert it to char)

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

              union {
              double d;
              char[8] c;
              } d2c;

              1 Reply Last reply
              0
              • A arr cpp

                how to convert from numeric types (such as double, int, long,...) to char[]? (i want to show the number in a window, so i need to convert it to char)

                A Offline
                A Offline
                abbiyr
                wrote on last edited by
                #7

                Hi there. While sprintf works, it is really a C solution. I just wanted to show you a C++ solution for creating a string to display by using streams. #include // your numerical data double num1 = 3.143; // an output stream std::ostringstream outStream; std::string outString; outStream << "Value of double is : " << num1; // if you want a standard c++ string from the stream outString = outStream.str(); // VC++ stuff. Lets write the string to a label (need to create a System::String) label1->Text = gcnew String(outStream.str().c_str()); Using the ostringstream, you will not have to worry about the size of your char array, or have a ptr to char and do any memory allocation/cleanup. All done for you. Cheers

                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