>I get this list as an email, not a threaded bulletin board or news group.
>Therefore, I can't search the archives.

Here you go, slightly stripped down. Probably needs modification for 
doubles and precision. Let me know if you have any questions.

Regards,
Steve Mann

# # #

/************************************
  * FloatToString
  * Convert a floating point # to a localized string.
  * Put the result in global string tempStr.
* If its length exceed maxDigits, shorten it and insert ">" to 
indicate overflow
* Ksep & DSep are globals containing thousands and decimal separators
  ************************************/

void FloatToString ( float val, UInt8 precision, UInt8  maxDigits ) {

        UInt32  ival, ival2;
        float   fval;
        Int16   i, offset;
        Char    part2 [10], remainder [10];

// get the LHS of the floating point number

        ival = ( long ) val;
        StrIToA ( tempStr, val ); // make it a string, put into global tempStr

// get the fractional part. max precision = 7

        if ( precision > 0 ) {

                part2 [ 0 ] = Dsep;
                part2 [ 1 ] = NULL;

                StrCat ( tempStr, part2);
                fval = val - ival; // get fractional part
                part2 [ 0 ] = NULL;

//      add leading zeros to the fractional part

                if ( fval > 0.0 ) {

                        for ( i = 0; i < 7; i++ ) {
                                fval = fval * 10.0;
                                if ( fval < 1.0 )
                                        StrCat ( part2, "0" );
                        }

// convert the rest of the fractional part to a usable integer and 
add it to the string

                        ival2 = ( long ) ( fval ); // convert 
remainder to integer
                        StrIToA ( remainder, ( long ) ival2 ); // add to string
                        StrCat ( part2, remainder );
                }

// zero fill the fraction to the right with trailing zeros

                for ( i = StrLen ( part2 ); i < 7; i++ )
                        StrCat ( part2, "0" );

// truncate the fractional part if necessary, to the prefsP->precision.

                if ( precision < StrLen ( part2 ) )
                                part2 [ precision ] = NULL;

// add the fraction to the final result

                StrCat ( tempStr, part2 );
        }

// the number is too large for conversion, fill it with overflow indicators

        if ( StrLen ( tempStr ) > maxDigits ) {

                for ( i = 0; i  < StrLen ( tempStr ); i++ ) {
                        if (( tempStr [ i ] >= '0' ) && ( tempStr [ i 
] <= '9' ))
                                tempStr [ i ] = '>';
                }

// now shorten it so it fits

                offset = StrLen ( tempStr ) - maxDigits;
                for ( i = 0; i <= ( maxDigits + 1 ); i++ ) {
                        tempStr [ i ] = tempStr [ i + offset ];
}       }       }

-- 
-------------------------------------------
Creative Digital Publishing Inc.
1315 Palm Street, San Luis Obispo, CA 93401-3117
-------------------------------------------
805.784.9461              805.784.9462 (fax)
[EMAIL PROTECTED]       http://www.cdpubs.com

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to