mfc >> Noob Question CString to Float conversion

by Rik Irving » Mon, 24 Nov 2003 02:41:20 GMT

Hey guys - I am having difficulty in converting a CString to a float value
to allow me to do calculations with it.

Any help would be appreciated.

Thanks.




mfc >> Noob Question CString to Float conversion

by David Robbins » Mon, 24 Nov 2003 03:01:15 GMT


try atof()








mfc >> Noob Question CString to Float conversion

by Mihajlo Cvetanovic » Mon, 24 Nov 2003 03:42:21 GMT




CString sString( _T("1.5 1.00000005") );
float fFloat;
double fDouble;

// sscanf returns the number of fields converted, here there are 2
if ( _stscanf( sString, _T("%f %lf"), &fFloat, &fDouble ) == 2 )
{
FloatsAreAllYours( fFloat, fDouble );
}
else
{
ErrorIsAllYours();
}

Observe the value for fDouble. It'll not be exactly 1.00000005...



Similar Threads

1. array<float>^ to float[] conversion

xxx wrote:
> Hi all, i'm new in visual c++ and i'm having troubles converting types.
> Let me explain: i have an unmanaged c++ function that wants an float* 
> parameter but i have an array<float>^, how i can covert it?
> the following code doesn't show up any error during compile time but 
> crashes at runtime telling "unrecognized or unsupported array type":
> 
> array<float>^ vals = gcnew array<float>(dimension);
> pin_ptr<float>ss=&vals[0];                   
> unmanaged_function(ss);
> 
> TIA

ops, substitute float* with float[] (a native array)

2. array<float>^ to float* conversion

3. IBM float to IEEE float conversion

4. Float to int conversion by using two int variables for representation of the float variable

5. Problem with float to int conversion by using two int variables for representing the float number

6. Problem with float to int conversion by using two int variables for representing the float number

7. Problem with float to int conversion by using two int variables for representing the float number

8. Problem with float to int conversion by using two int variables for representing the float number