|
-
Aug 27th, 2001, 08:15 PM
#1
Thread Starter
Hyperactive Member
simple conversion?
how can I convert a float to a char?
Matt 
-
Aug 27th, 2001, 08:17 PM
#2
you could cast it as an int:
PHP Code:
char chrTest = (int)(3.2);
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Aug 27th, 2001, 08:22 PM
#3
Thread Starter
Hyperactive Member
i tried
Code:
char sztext = (int)(result);
MessageBox(NULL,sztext,"testing",MB_OK);
it says as a error-annot convert parameter 2 from 'char' to 'const char *'
Matt 
-
Aug 27th, 2001, 08:24 PM
#4
Code:
char* sztext = (int)(result);
MessageBox(NULL,sztext,"testing",MB_OK);
try that
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Aug 27th, 2001, 08:27 PM
#5
Thread Starter
Hyperactive Member
tryed that earlier I get the error
cannot convert from 'int' to 'char *'.
also I mistyped- Im converting double to char if it matters.
Matt 
-
Aug 27th, 2001, 08:27 PM
#6
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
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Aug 27th, 2001, 08:29 PM
#7
Thread Starter
Hyperactive Member
but won't that truncate 3.2 to 3?
Matt 
-
Aug 27th, 2001, 08:46 PM
#8
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 );
}
-
Aug 28th, 2001, 05:30 PM
#9
Thread Starter
Hyperactive Member
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.
Matt 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|