Results 1 to 9 of 9

Thread: simple conversion?

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    simple conversion?

    how can I convert a float to a char?
    Matt

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  3. #3

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    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

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  5. #5

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    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

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  7. #7

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    but won't that truncate 3.2 to 3?
    Matt

  8. #8
    jim mcnamara
    Guest
    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 mainvoid )
    {
       
    char  buffer[200], s[] = "computer"'l';
       
    int   i 35j;
       
    float fp 1.7320534f;

       
    /* Format and print various data: */
       
    j  sprintfbuffer,     "\tString:    %s\n");
       
    += sprintfbuffer j"\tCharacter: %c\n");
       
    += sprintfbuffer j"\tInteger:   %d\n");
       
    += sprintfbuffer j"\tReal:      %f\n"fp );

       
    printf"Output:\n%s\ncharacter count = %d\n"buffer);


  9. #9

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    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
  •  



Click Here to Expand Forum to Full Width