converting to different data types 
Author Message
 converting to different data types

Ok. My problem is the same as last time. I am trying to convert CString's (3
of them) int to float data types and then back to CString's. Can some one
please tell how they were able to do this. The reason why I am converting
them is so that I can use them them in some arithmatic problems.

Thanx,
cm



Tue, 22 Apr 2003 20:58:13 GMT  
 converting to different data types

CString val("12.45");
float f = atof( val );

Quote:

> Ok. My problem is the same as last time. I am trying to convert CString's (3
> of them) int to float data types and then back to CString's. Can some one
> please tell how they were able to do this. The reason why I am converting
> them is so that I can use them them in some arithmatic problems.

> Thanx,
> cm



Tue, 22 Apr 2003 21:07:40 GMT  
 converting to different data types
You could use the atof / wtof runtime methods to convert from string to
double, and use the Format() method of the CString class to convert back to
string:

 CString sNumber = _T("1.23456");
 double d = atof(sNumber);
 d = d / 2;
 sNumber.Format(_T("%f"), d);

Or, if you need to take locale setup into consideration (handle different
decimal separators) you could go the way via a VARIANT and use
VariantChangeType() / VariantChangeTypeEx() but it's more work.

Arild Bakken
System Developer
---
Inmeta AS - http://www.inmeta.com


Quote:

> Ok. My problem is the same as last time. I am trying to convert CString's
(3
> of them) int to float data types and then back to CString's. Can some one
> please tell how they were able to do this. The reason why I am converting
> them is so that I can use them them in some arithmatic problems.

> Thanx,
> cm



Tue, 22 Apr 2003 21:15:54 GMT  
 converting to different data types
thanx, is there any way I can just have 2 decimal places?

cm


Quote:
> Ok. My problem is the same as last time. I am trying to convert CString's
(3
> of them) int to float data types and then back to CString's. Can some one
> please tell how they were able to do this. The reason why I am converting
> them is so that I can use them them in some arithmatic problems.

> Thanx,
> cm



Tue, 22 Apr 2003 21:54:22 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Converting different data types from a socket.

2. Different value when converting into different type

3. Type conversion-How can I convert cstring data type to char*

4. converting BSTR data type to common string type!

5. System.Data.SqlClient.SqlException: Error converting data type varchar to numeric

6. getting CONVERT function info different data sources

7. getting CONVERT function info different data sources

8. conversion between different data type

9. Different Data Types in a File

10. Templates with different data types.

11. Array of different data types.

12. ATL data type for VB Object data Type

 

 
Powered by phpBB® Forum Software