newsgroups-index (beta)

Current group: codewarrior.palm

convert double to string

convert double to string  
desalvo123 at comcast.net
 Re: convert double to string  
Alex
From:desalvo123 at comcast.net
Subject:convert double to string
Date:6 Jan 2005 15:11:53 -0800
I need to convert a double to a string. I've been using sprintf on a
Pocket PC, but I don't know what to use for Palm OS. I need to be able
to set the precision too. Please help! Thanks.
From:Alex
Subject:Re: convert double to string
Date:Fri, 7 Jan 2005 09:10:48 -0000
Found that function somewhere on google:

void doubleToStr (char* str, double flpNumber, UInt8 numFractDigits)
{
double flpIP, zeros, round, remainder;
UInt8 i, strLen;
char sign = ' ';

if (flpNumber < 0.0)
{
flpNumber = -flpNumber;
sign = '-';
}

zeros = pow (10, numFractDigits); // get the rounding constant
round = 0.5 / zeros;

flpNumber = modf (flpNumber + round, &flpIP); // get integer and
fractional parts

str[0] = sign;
StrIToA (&str[1], (UInt16)flpIP);
strLen = StrLen (str); // put in the decimal point and terminate the
string
str[strLen] = '.';
str[numFractDigits + strLen + 1] = '\0';

flpNumber = flpNumber * zeros; // fractional part

for (i = numFractDigits + strLen; i > strLen; i--) // convert the integer
part
{
remainder = fmod (flpNumber, 10);
str[i] = remainder + 0x30;
flpNumber /= 10;
}
}

Hope that helps, Alex

wrote in message
news:1105053113.446420.124810@z14g2000cwz.googlegroups.com...
>I need to convert a double to a string. I've been using sprintf on a
> Pocket PC, but I don't know what to use for Palm OS. I need to be able
> to set the precision too. Please help! Thanks.
>
   

Copyright © 2006 newsgroups-index   -   All rights reserved   -   Impressum