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. convert double to char!

convert double to char!

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresquestion
4 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.
  • C Offline
    C Offline
    catngo
    wrote on last edited by
    #1

    how do you convert double to char? i mean to keep it the way it is as double for display. exp: 3.5 will be 3.5 as char (maybe to CString or array since this is 3 characters)

    M E 2 Replies Last reply
    0
    • C catngo

      how do you convert double to char? i mean to keep it the way it is as double for display. exp: 3.5 will be 3.5 as char (maybe to CString or array since this is 3 characters)

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

      CString str;
      double dblValue = 2.25;

      str.Format("%0.2f",dblValue);
      //0.2 means 2 chars after decimal

      Hope it helps :) C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg

      C 1 Reply Last reply
      0
      • M Monty2

        CString str;
        double dblValue = 2.25;

        str.Format("%0.2f",dblValue);
        //0.2 means 2 chars after decimal

        Hope it helps :) C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg

        C Offline
        C Offline
        catngo
        wrote on last edited by
        #3

        thank you!

        1 Reply Last reply
        0
        • C catngo

          how do you convert double to char? i mean to keep it the way it is as double for display. exp: 3.5 will be 3.5 as char (maybe to CString or array since this is 3 characters)

          E Offline
          E Offline
          Ellis Li
          wrote on last edited by
          #4

          If you use CString to store the value, try the "format" method. If you use char * , try to use "sprintf". If the result will put into unicode string, try "swprintf" Ellis Li

          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