how can I convert a float to a char?
Printable View
how can I convert a float to a char?
you could cast it as an int:
:)PHP Code:char chrTest = (int)(3.2);
i tried
it says as a error-annot convert parameter 2 from 'char' to 'const char *'Code:char sztext = (int)(result);
MessageBox(NULL,sztext,"testing",MB_OK);
try thatCode:char* sztext = (int)(result);
MessageBox(NULL,sztext,"testing",MB_OK);
tryed that earlier I get the error
cannot convert from 'int' to 'char *'.
also I mistyped- Im converting double to char if it matters.
note that that will display the 3rd ASCII character. I fyou what to convert 3.2 into "3.2", then I would suggest using the itoa() function
:)
but won't that truncate 3.2 to 3?
t'ash dee aay yah. (except the char set doesn't support Athapascan symbols..)
Trans: Is that all there is....
use sprintf.
PHP Code:void main( void )
{
char buffer[200], s[] = "computer", c = 'l';
int i = 35, j;
float fp = 1.7320534f;
/* Format and print various data: */
j = sprintf( buffer, "\tString: %s\n", s );
j += sprintf( buffer + j, "\tCharacter: %c\n", c );
j += sprintf( buffer + j, "\tInteger: %d\n", i );
j += sprintf( buffer + j, "\tReal: %f\n", fp );
printf( "Output:\n%s\ncharacter count = %d\n", buffer, j );
}
thanks, also when i want to make it so it only displays two digits after the decimal point I know I use cout.precison(2), right? I used it and it made no difference.