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. CString

CString

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

    how to add a number to a string? can i convert from a string to double and reverse? e.g CString (or string) text = "37"; i want to add 4e3:rolleyes: to this value??!!!!!!!

    J C A 3 Replies Last reply
    0
    • O Oriented

      how to add a number to a string? can i convert from a string to double and reverse? e.g CString (or string) text = "37"; i want to add 4e3:rolleyes: to this value??!!!!!!!

      J Offline
      J Offline
      John R Shaw
      wrote on last edited by
      #2

      Lookup the "Data Conversion" functions in the MSDN library (atof). Basicaly you convert the string to a number add the new value to the old and then use CString::Format() function to replace the string with the new value.

      double old = atof(&string); // Get current value
      old += new; // Add new value to old value
      string.Format(_T("%f"),old); // replace sting with new value

      or something simular. INTP

      1 Reply Last reply
      0
      • O Oriented

        how to add a number to a string? can i convert from a string to double and reverse? e.g CString (or string) text = "37"; i want to add 4e3:rolleyes: to this value??!!!!!!!

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

        Hi, I create this function to convert from double to CString. var is the number to be converted ndec Number of digits after decimal point CString do2CStr(double var,int ndec) { int decimal, sign; char *buffer; buffer = _fcvt( var, ndec ,&decimal, &sign ); int len=strlen(buffer); CString number(buffer); CString valor; if(sign)//negative number valor="-"+number.Left(decimal)+"."+number.Right(len-decimal); else valor=number.Left(decimal)+"."+number.Right(len-decimal); return valor; } Daniel Cespedes "There are 10 types of people, those who understand binary and those who do not" "Santa Cruz de la Sierra Paraiso Terrenal!" daniel.cespedes@ieee.org

        C 1 Reply Last reply
        0
        • C Cambalindo

          Hi, I create this function to convert from double to CString. var is the number to be converted ndec Number of digits after decimal point CString do2CStr(double var,int ndec) { int decimal, sign; char *buffer; buffer = _fcvt( var, ndec ,&decimal, &sign ); int len=strlen(buffer); CString number(buffer); CString valor; if(sign)//negative number valor="-"+number.Left(decimal)+"."+number.Right(len-decimal); else valor=number.Left(decimal)+"."+number.Right(len-decimal); return valor; } Daniel Cespedes "There are 10 types of people, those who understand binary and those who do not" "Santa Cruz de la Sierra Paraiso Terrenal!" daniel.cespedes@ieee.org

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Why, doesn't CString::Format work for you ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

          1 Reply Last reply
          0
          • O Oriented

            how to add a number to a string? can i convert from a string to double and reverse? e.g CString (or string) text = "37"; i want to add 4e3:rolleyes: to this value??!!!!!!!

            A Offline
            A Offline
            akirachen
            wrote on last edited by
            #5

            atoi() itoa()

            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