I just asked the same question, and apparently there is a common routine
called GetStringFromDouble that, although not part of the SDK, is a
function that has been publicly posted and is in common use. I was
referred to the archives for this newsgroup, but could not find it there.
I found it in another newsgroup archive (not one of Palm's) through a
Google search and will post it below.
Pass the routine your destination string, the floating point number, and
the number of digits after the decimal point desired.
//********************************************************************
// GetStringFromDouble()
//********************************************************************
//
// Gets string from double, and rounds to the appropriate number of
// decimal points.
//
// Taken from Palm Dev Forum
//
//********************************************************************
void GetStringFromDouble(Char* str, double dblNum, Int16 numFractDigits)
{
double flpIP, zeros, round;
Int32 remainder, longNumber;
Int16 i, strLen;
Char buffer[16];
str[0] = 0;
if (dblNum < 0.0)
{
dblNum = -dblNum;
StrCat(str, "-");
}
zeros = 1.0;
for (i = 0; i < numFractDigits; i++)
{
zeros *= 10.0;
}
round = 0.5 / zeros;
dblNum += round;
flpIP = (Int32) dblNum;
dblNum -= flpIP;
StrIToA(buffer, (Int32) flpIP);
StrCat(str, buffer);
strLen = (Int16) StrLen(str);
StrCat(str, "."); // put in the decimal point and terminate the string
str[numFractDigits + strLen + 1] = '\0';
longNumber = (Int32) (dblNum * zeros); // fractional part
for (i = numFractDigits + strLen; i > strLen; i--)
{
remainder = longNumber % 10; // convert the integer part
str[i] = (Char) (remainder + 0x30);
longNumber /= 10;
}
}
In your message regarding Displaying Float Values in simple format dated
Tue, 20 Sep 2005 13:53:11 -0000, Jeetu said that ...
> Hi Folks,
> I have a problem regarding Float Values,i m storing float value
into Database and Displaying it in the text Field,but it is showing me in
exponential Format.I dont want to display it in exponential format.
>
> I have used Float Fn's Like:-
>
> FlpBufferAToF() for converting the Value into Float and then assingning it
to FlpDouble type value.
>
> Ex.) if I enter the value in my TextField 123.45 it stores the value in PDB
in exponential Format(i.e 1.23...e10-3 something).
> But while displaying i dont want to display the value in exponential format
i.e i want to display the value as it was entered in the PDB. (i.e 123.45 only).
>
> Any suggestions how to exactly work on Float values or to display the
exponential value in normal float Format.
>
>
>
> --
> For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/
>
>
>
--
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/