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 char* to double and back

convert char* to double and back

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

    I have a char* that holds a numeric value of for example: 172,500 and I want to multiply this by another number and write the contents back to a new char*. Could someone give some example code on how to easily achieve this?

    S N 2 Replies Last reply
    0
    • A Andy H

      I have a char* that holds a numeric value of for example: 172,500 and I want to multiply this by another number and write the contents back to a new char*. Could someone give some example code on how to easily achieve this?

      S Offline
      S Offline
      sw thi
      wrote on last edited by
      #2

      You can use atoi and itoa functions to achieve this. atoi - converts string to int. itoa - converts int to string.

      1 Reply Last reply
      0
      • A Andy H

        I have a char* that holds a numeric value of for example: 172,500 and I want to multiply this by another number and write the contents back to a new char*. Could someone give some example code on how to easily achieve this?

        N Offline
        N Offline
        Nishad S
        wrote on last edited by
        #3

        Andy H wrote:

        for example: 172,500

        Actually is there a comma (,) ?

        - NS -

        A 1 Reply Last reply
        0
        • N Nishad S

          Andy H wrote:

          for example: 172,500

          Actually is there a comma (,) ?

          - NS -

          A Offline
          A Offline
          Andy H
          wrote on last edited by
          #4

          There is a (,) in the string. What I think I will do is write a class that can cater for all eventualities, as there is also a possibility of the number being in scientific notation, just to make matters worse!

          N 1 Reply Last reply
          0
          • A Andy H

            There is a (,) in the string. What I think I will do is write a class that can cater for all eventualities, as there is also a possibility of the number being in scientific notation, just to make matters worse!

            N Offline
            N Offline
            Nishad S
            wrote on last edited by
            #5

            You can do it simple... first filter out the comma. If you are using the CString, use str.Remove(',') so that the comma will be filtered. Then you can convert it to integer using atol, atoi, etc., or _ttol, _ttoi, etc.

            - NS -

            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