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. GetDlgItemText getting a float

GetDlgItemText getting a float

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
5 Posts 4 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.
  • J Offline
    J Offline
    Johpoke
    wrote on last edited by
    #1

    Ok, so im running MS Visual C++ 6.0, programming a C++ MFC program. Im my dialog i have a edit box (locked to numbers) were the user will type in a float (a price) So then i have to use GetDlgItemText go get the float into a CString (cant use getdlgitemint as it looses the decimals) but now i then need to convert the cstring (containing someting like 29.88) into a normal float, like this: Main->Price=cstringprice; ive tried loads of things, like atof.. but all of them make errors when trying to use the variable it set so got any better ideas of getting a float from the dialog into a float? or converting what GetDlgItemText brings into a float? thanks!

    /Johannes

    W J H T 4 Replies Last reply
    0
    • J Johpoke

      Ok, so im running MS Visual C++ 6.0, programming a C++ MFC program. Im my dialog i have a edit box (locked to numbers) were the user will type in a float (a price) So then i have to use GetDlgItemText go get the float into a CString (cant use getdlgitemint as it looses the decimals) but now i then need to convert the cstring (containing someting like 29.88) into a normal float, like this: Main->Price=cstringprice; ive tried loads of things, like atof.. but all of them make errors when trying to use the variable it set so got any better ideas of getting a float from the dialog into a float? or converting what GetDlgItemText brings into a float? thanks!

      /Johannes

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

      atof() should work just fine. Perhaps you could show the code for your converting and we may be able to point out the error.

      1 Reply Last reply
      0
      • J Johpoke

        Ok, so im running MS Visual C++ 6.0, programming a C++ MFC program. Im my dialog i have a edit box (locked to numbers) were the user will type in a float (a price) So then i have to use GetDlgItemText go get the float into a CString (cant use getdlgitemint as it looses the decimals) but now i then need to convert the cstring (containing someting like 29.88) into a normal float, like this: Main->Price=cstringprice; ive tried loads of things, like atof.. but all of them make errors when trying to use the variable it set so got any better ideas of getting a float from the dialog into a float? or converting what GetDlgItemText brings into a float? thanks!

        /Johannes

        J Offline
        J Offline
        Johpoke
        wrote on last edited by
        #3

        Ah solved it, problem was elsewhere thanks anyway!

        /Johannes

        1 Reply Last reply
        0
        • J Johpoke

          Ok, so im running MS Visual C++ 6.0, programming a C++ MFC program. Im my dialog i have a edit box (locked to numbers) were the user will type in a float (a price) So then i have to use GetDlgItemText go get the float into a CString (cant use getdlgitemint as it looses the decimals) but now i then need to convert the cstring (containing someting like 29.88) into a normal float, like this: Main->Price=cstringprice; ive tried loads of things, like atof.. but all of them make errors when trying to use the variable it set so got any better ideas of getting a float from the dialog into a float? or converting what GetDlgItemText brings into a float? thanks!

          /Johannes

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

          You can use of

          CString str;
          str.Format("%lf",28.29);

          But what errors when used of atof?


          WhiteSky


          1 Reply Last reply
          0
          • J Johpoke

            Ok, so im running MS Visual C++ 6.0, programming a C++ MFC program. Im my dialog i have a edit box (locked to numbers) were the user will type in a float (a price) So then i have to use GetDlgItemText go get the float into a CString (cant use getdlgitemint as it looses the decimals) but now i then need to convert the cstring (containing someting like 29.88) into a normal float, like this: Main->Price=cstringprice; ive tried loads of things, like atof.. but all of them make errors when trying to use the variable it set so got any better ideas of getting a float from the dialog into a float? or converting what GetDlgItemText brings into a float? thanks!

            /Johannes

            T Offline
            T Offline
            ThatsAlok
            wrote on last edited by
            #5

            try _ttod

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you

            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