Hola
you can use this function:
void doubleToStr (char *str,double flpNumber,Int numFractDigits)
EJ:
double var1;
string numero[10];
doubleToStr(numero,var1,2);
****************************************************************
void doubleToStr (char *str,double flpNumber,Int numFractDigits)
{
long longNumber;
double flpIP,zeros,round;
int i,strLen,remainder;
char sign=' ';
if (flpNumber<0.0)
{ flpNumber=-flpNumber;
sign='-'; }
zeros =1.0;
for (i=0;i<numFractDigits;i++)
zeros*=10;
round=0.5/zeros;
flpNumber +=round;
flpIP=(long) flpNumber;
flpNumber = flpNumber - flpIP;
str[0]=sign;
if (sign=='-')
StrIToA(&str[1],(long) flpIP);
else
StrIToA(&str[0],(long) flpIP);
strLen=StrLen(str);
str[strLen]='.';
str[numFractDigits + strLen + 1] ='\0';
longNumber = flpNumber * zeros;
for (i=numFractDigits + strLen;i>strLen; i--)
{remainder = longNumber %10;
str[i]=remainder + 0x30;
longNumber /=10;
}
}
***********************************************************
Adios..............................
>From: "Alan Ingleby" <[EMAIL PROTECTED]>
>Reply-To: "Palm Developer Forum" <[EMAIL PROTECTED]>
>To: "Palm Developer Forum" <[EMAIL PROTECTED]>
>Subject: Re: Bug in FloatToString
>Date: Thu, 5 Sep 2002 08:59:08 +1000
>
>Search the archives for GetStringFromDouble. Email me directly if you need
>help.
>
>Alan Ingleby
>
>"Andreas Zankl" <[EMAIL PROTECTED]> wrote in message
>news:94876@palm-dev-forum...
> >
> > Unfortunately my calculation is more complicated than that. It uses a
>whole
> > lot of MathLib functions.Does anybody know a better function than
> > FloatToString?
> > Andreas.
> >
> > P.S.: By mistake I sent my original posting again, sorry for that.
> >
> >
> >
> > Aaron Ardiri schrieb:
> >
> > > > After searching the archives I found the following routine from
>Bradly
> > > > Barton to convert float variables to string. Unfortunately it is not
> > > > working correctly: 6.964559 is converted to 6.10 (for round = 1).
>That'
> > > > s obviously wrong and there is also one digit more than there should
>be
> > > > (for round =1). It works correctly with values not so close to the
>next
> > > > full integer (7 in this example, 6.55555 works OK) Can anybody fix
> > > > this? Is Bradly Barton still out there?
> > >
> > > how about not using floats? :)
> > >
> > > john posted a nice google hint for you - take a read of this. the
> > > best way to ensure that a float is printed correctly is to not
> > > use floating point. try using another mechanism to represent your
> > > data.
> > >
> > > for example, monetary values can be stored x100. you print it
> > > as X.XX by dividing by 100, adding a '.' and, printing the
> > > modulus of 100 (with a leading zero if needed) to generate the
> > > string for display on the screen.
> > >
> > > ---
> > > Aaron Ardiri
> > > CEO - CTO
> > > Mobile Wizardry
> > > http://www.mobilewizardry.com/
> >
> >
> >
>
>
>
>--
>For information on using the Palm Developer Forums, or to unsubscribe,
>please see http://www.palmos.com/dev/support/forums/
_________________________________________________________________
�nase al mayor servicio mundial de correo electr�nico:
http://www.hotmail.com/es
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/