Results 1 to 5 of 5

Thread: SetDlgItemInt \ SetDlgItemText

  1. #1
    Sc0rp
    Guest

    Unhappy SetDlgItemInt \ SetDlgItemText

    I'm trying to put a float into an edit control, but I can't seem to use SetDlgItemInt because it applies only to integers, and I don't know how to convert a floating point number to a char*.

    Any suggestions?

  2. #2
    jim mcnamara
    Guest
    Code:
    void intToChar(double i, char *t){
              sprintf(t,"%8.0f",i);
    }
    usage:

    double z = 12345.6;
    char zz[20];
    intToChar(z,zz);

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    _fcvt
    Converts a floating-point number to a string.

    char *_fcvt( double value, int count, int *dec, int *sign );

    Function Required Header Compatibility
    _fcvt <stdlib.h> Win 95, Win NT


    For additional compatibility information, see Compatibility in the Introduction.

    Libraries

    LIBC.LIB Single thread static library, retail version
    LIBCMT.LIB Multithread static library, retail version
    MSVCRT.LIB Import library for MSVCRT.DLL, retail version


    Return Value

    _fcvt returns a pointer to the string of digits. There is no error return.

    Parameters

    value

    Number to be converted

    count

    Number of digits after decimal point

    dec

    Pointer to stored decimal-point position

    sign

    Pointer to stored sign indicator

    Remarks

    The _fcvt function converts a floating-point number to a null-terminated character string. The value parameter is the floating-point number to be converted. _fcvt stores the digits of value as a string and appends a null character ('\0'). The count parameter specifies the number of digits to be stored after the decimal point. Excess digits are rounded off to count places. If there are fewer than count digits of precision, the string is padded with zeros.

    Only digits are stored in the string. The position of the decimal point and the sign of value can be obtained from dec and sign after the call. The dec parameter points to an integer value; this integer value gives the position of the decimal point with respect to the beginning of the string. A zero or negative integer value indicates that the decimal point lies to the left of the first digit. The parameter sign points to an integer indicating the sign of value. The integer is set to 0 if value is positive and is set to a nonzero number if value is negative.

    _ecvt and _fcvt use a single statically allocated buffer for the conversion. Each call to one of these routines destroys the results of the previous call.

    Example

    /* FCVT.C: This program converts the constant
    * 3.1415926535 to a string and sets the pointer
    * *buffer to point to that string.
    */

    #include <stdlib.h>
    #include <stdio.h>

    void main( void )
    {
    int decimal, sign;
    char *buffer;
    double source = 3.1415926535;

    buffer = _fcvt( source, 7, &decimal, &sign );
    printf( "source: %2.10f buffer: '%s' decimal: %d sign: %d\n",
    source, buffer, decimal, sign );
    }
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  4. #4
    Sc0rp
    Guest
    Thanks, that helped.

    Is there a way to do this using the string class from the standard library?

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    How about a stringstream?:
    Code:
    #include <sstream> // or is it strstream? It changed names somewhere
    
    string double2string(double dVal) {
        ostringstream oss;
        oss << dVal;
        return oss.str();
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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