Hi Sergio,
I had this problem last week and Thiago Rossato sent me this function.
I hope this help you too.

Cheers (um abra�o)
Roberto Amorim


void FloatToString (float value, char * buffer, int round)
{
 long iValue;
 float dDecimal;
 long iDecValue;
 int i;
 char sResult[50];
 char sDecimal[50];
 char sTemp[50];

 iValue = value;
 dDecimal = value - iValue;
 if (dDecimal < 0.000000001) dDecimal = 0;

 // Convert integer portion to string
 StrIToA(sResult, iValue);
 if (StrLen(sResult) < 1) StrCopy(sResult, "0");
 StrCat(sResult, ".");

 // Round decimal portion
 for (i = 1; i <= round; i++)
  dDecimal = dDecimal * 10;

 iDecValue = dDecimal;
 if (dDecimal - iDecValue >= 0.5) iDecValue++;

 // Add decimal portion
 StrIToA (sDecimal, iDecValue);

 // Add leading zeros if neccessary
 if (StrLen (sDecimal) < round)
  for (i = 1; i <= round - StrLen(sDecimal); i++)
   StrCat (sResult, "0");
 StrCat (sResult, sDecimal);

 // Copy into return string
 StrCopy (buffer, sResult);
}



Sergio Carvalho wrote:
> 
> Hi,
> 
> Are there any functions that convert Float variables to/from strings?
> StrPrintf doesn't seem to support the %f  format specification...
> 
> --
> Sergio Carvalho
> ---------------
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> 
> If at first you don't succeed, skydiving is not for you
> 
> ---
> For information on using the Palm Developer Forums, or to unsubscribe, please see 
><http://www.palm.com/devzone/mailinglists.html>.

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

Reply via email to