5 Replies - 5105 Views - Last Post: 19 April 2007 - 03:24 PM Rate Topic: -----

#1 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Question: Calculator in Visual C++ (MFC)

Posted 01 April 2007 - 02:12 PM

Hi, (I'm using the MFC exe) I have an Edit box which can only have one variable for a Value which is usually of type CString, but I want that string to be converted to a type float so that I can work with the numbers, so my questions would be is there any function that I can use, or any idea how can i do this?
NOTE:This is a question and there is no point of using code on my side since this is Visual C++.

Is This A Good Question/Topic? 0
  • +

Replies To: Question: Calculator in Visual C++ (MFC)

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Question: Calculator in Visual C++ (MFC)

Posted 01 April 2007 - 03:09 PM

Hmm....can you feed a CString value to sprintf()? Have you tried with the normal string to number conversions?
Was This Post Helpful? 0
  • +
  • -

#3 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Question: Calculator in Visual C++ (MFC)

Posted 01 April 2007 - 04:17 PM

The thing is that the Edit box don't have a normal string support.
About sprintf() I think I can't use it since I work with Dialog based App.

I'll get back on this after I clear some things with Visual C++.
Was This Post Helpful? 0
  • +
  • -

#4 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Question: Calculator in Visual C++ (MFC)

Posted 02 April 2007 - 04:37 PM

There are a few ways to get a float out of a string.

The long way, you can write your own parsing routine. not so much fun, but it will work the way you want it to.

That asside there are a few in standard libraries. atof() works well for string to float in math.h or cmath, then there is strtod() in the stdlib.h, and lastly _atold() also math.h. There each work a little differently so make sure you look them up.
Was This Post Helpful? 0
  • +
  • -

#5 cool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-April 07

Re: Question: Calculator in Visual C++ (MFC)

Posted 14 April 2007 - 11:33 AM

you can go to class wizard and change the variable type to float (Cstring will be shown as default)
Was This Post Helpful? 0
  • +
  • -

#6 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Question: Calculator in Visual C++ (MFC)

Posted 19 April 2007 - 03:24 PM

Thank you for all the answers.
well for the record I did use float as a Value varable with name e.g.
so that ehn I wanted it in a string I use:
CString tmp;
tmp.Format("The value of the float is %f", x);

This post has been edited by PennyBoki: 19 April 2007 - 03:29 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1