static void DoubleToString (double val, char * dstP)
{

 char  str[MAX_LHS_DIGITS + 5];
 double   lhsd;
 double   rhsd;

 UInt8  digitCnt = 0;
 UInt8  strIdx = sizeof(str) - 1;
 UInt8  len;

 long long  digitll;
/* int   digitll; usar numeros enteros en caso de que ande mal el long */
 double  digitd;

 char  digit;
 char  * altdstP = dstP;



 if (val < 0.0)
 {
  *dstP++ = '-';
  val = - val;
 }

 lhsd = (double) (long long) val;
 rhsd = val - lhsd;
 str[strIdx--] = '\0';

 while (lhsd >= 1.0 && digitCnt < MAX_LHS_DIGITS)
 {
  if ((digitCnt % 3) == 0 && digitCnt > 0)
   str[strIdx--] = ',';

  digitll = (long long) (lhsd / 10.0);
/*  digitll = (int) (lhsd / 10.0); usar numeros enteros en caso de que ande
mal el long */
  digitd = ((double) digitll) * 10.0;
  digit = (char) ('0' + (char)(lhsd - digitd));

  digitCnt++, str[strIdx--] = digit;
  lhsd = (double) digitll;
 }

 /* terminamos con la parte izquierda */

 StrCopy(dstP, &str[strIdx + 1]);

 dstP = dstP + StrLen(dstP);
 len = (UInt8) StrLen(altdstP);
 digitCnt = 0;

 len++, *dstP++ = '.';

 while (digitCnt < 2)
 {
  digitCnt++;

  if (rhsd > 0.01)
  {

   rhsd = rhsd * 10.0;
   rhsd += 0.0001;
   digitll = (long long) rhsd;

/*   digitll = (int) rhsd; usar numeros enteros en caso de que ande mal el
long */
   digit = (char) ((char)(digitll) + '0');

   len++, *dstP++ = digit;
   rhsd = rhsd - (double) digitll;
  }
  else
  {
   len++, *dstP++ = '0';
  }
 }

 *dstP++ = '\0';

}


----- Original Message -----
From: "jose luis garcia" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Friday, February 23, 2001 12:12 PM
Subject: string to double , double to string routines


> Hello.
>
> How can i convert an double to string and a string to double ?
>
> thanks....
>
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to