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. Converting char* to double

Converting char* to double

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.
  • E Offline
    E Offline
    elelont2
    wrote on last edited by
    #1

    Hi, I have a char array like that represents a double, e.g "1.0004" If i use atof to get double then i get the value 1, since my locale is using , as decimal separator. But when i use istringstream i get the correct value. How is that possible? Does it convert BOTH the . and , to decimal separators? Regards

    _ 1 Reply Last reply
    0
    • E elelont2

      Hi, I have a char array like that represents a double, e.g "1.0004" If i use atof to get double then i get the value 1, since my locale is using , as decimal separator. But when i use istringstream i get the correct value. How is that possible? Does it convert BOTH the . and , to decimal separators? Regards

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      stringstream uses the locale information to do the conversion. You can use _atof_l to achieve the same result.

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++) (October 2009 - September 2013)

      Polymorphism in C

      E 1 Reply Last reply
      0
      • _ _Superman_

        stringstream uses the locale information to do the conversion. You can use _atof_l to achieve the same result.

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++) (October 2009 - September 2013)

        Polymorphism in C

        E Offline
        E Offline
        elelont2
        wrote on last edited by
        #3

        How does it explain my situation? I read that atof uses locale information, and my locale is using , as decimal separator - therefore it only gives me integer part of the double. My data however contains a . as decimal separator. http://stackoverflow.com/questions/1333451/c-locale-independent-atof[^]

        J 1 Reply Last reply
        0
        • E elelont2

          How does it explain my situation? I read that atof uses locale information, and my locale is using , as decimal separator - therefore it only gives me integer part of the double. My data however contains a . as decimal separator. http://stackoverflow.com/questions/1333451/c-locale-independent-atof[^]

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          atof() is part of the standard C library that uses the general 'C' locale by default while stringstream is C++ which uses the current system locale by default. You can use the setlocale()[^] function to change the locale for the standard C library functions (pass an empty string to use the environment's default locale).

          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