Wrox Programmer Forums
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 22nd, 2003, 08:19 PM
Registered User
 
Join Date: Sep 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default double to string?

I need to output a double to a static control. Is there any way to convert a double to a string? (I know about the SetDlgItemInt function, but I believe that only works for ints. I MUST make the output a double, or some data type that supports decimals) thanks, Chris

 
Old September 23rd, 2003, 08:19 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can use the MFC CString class to create a string object. One of the class members Format is able to do the conversion for you.

CString s;
double x;

x = 23.12345;
s.Format("%7.3f", x);
// Outputs 23.123
AfxMessageBox(s);

Hope this helps. You can read more about CString in the help file.

Larry Asher
 
Old September 23rd, 2003, 01:54 PM
Registered User
 
Join Date: Sep 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Excellent, that works great. One more Q though, :) How would I go about getting a double from an edit box also? Thanks

 
Old September 23rd, 2003, 01:58 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Going the other way, I believe you can use the atof() Function. This converts an ascii value to a real.

double x;

x = atof(m_dStringVal);

Hope that works.

Larry Asher
 
Old September 23rd, 2003, 02:34 PM
Registered User
 
Join Date: Sep 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually I found an even easier way. just associate a double with the edit control, and when you call UpdateData, you can then just use the member variable. THanks again for the help on output.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing Double Quotes from a string Durkee VB.NET 2002/2003 Basics 12 October 4th, 2007 12:10 PM
Removing Double Qoutes from string hexOffender VB.NET 2002/2003 Basics 2 June 26th, 2006 02:44 PM
Convert empty string to double adriant42 Excel VBA 2 June 8th, 2004 04:22 AM
casting double to String. chikodi Servlets 2 October 23rd, 2003 02:50 AM
String to Double conversion mkpriya VS.NET 2002/2003 3 October 21st, 2003 05:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.