i used this function to convert a string to a float:
double StrToDbl( CharPtr pString )
{
FlpCompDouble dObj;
dObj.fd = FlpAToF( pString );
return ( dObj.d );
}
i use a double var to hold information for the return value in the calling
function, which i then use to sum the values of multiple pStrings in a loop:
double dAmount;
for ( loop code )
{
dAmount += StrToDbl( pString );
}
the error produced by this code is such:
Link Error : cbook.c: '_d_add' referenced from 'drawTable' is undefined.
(which i know is a result of the adding line above ... if i comment it out
or hard-code a double value instead of the function it builds fine )
i also use this function to get a string from a float value:
CharPtr DblToStr( double pFloat )
{
FlpCompDouble flpObj;
CharPtr sFloat;
sFloat = "0";
// Convert a float to a string
flpObj.d = pFloat;
FlpFToA( flpObj.fd, sFloat );
return ( sFloat );
}
this compiles fine, but i get a bus error on the emulator when i run it
there.
does anyone know why it is so difficult to convert a float to string and
vice versa? please give me help with this ... this is an important piece of
the puzzle that i need to figure out, and i've exhausted all my resources
that i can think of right now.
thank you in advance,
-Dan-
#include <PalmTypes.h>
#include <PalmCompatibility.h>
the compiler says they don't exist. perhaps this is because i'm using
codewarrior lite. perhaps its a setting in the project settings that i
failed to set up. i'm still learning how codewarrior works, so any help
would be much appreciated. thank you
-Dan-
--
"Ben Combee" <com...@techwood.org> wrote in message
news:fb688Ky...@www.massena.com...
> "Jay Hong" <jh...@lancercorp.com> wrote in message
> news:djY#tGyqA...@www.massena.com...
> > What is a FlpCompDouble? (I searched the CW directory and could not find
> it)
> > Also, do you realize that FlpFtoA will give you a string in exponential
> > format?
>
> The whole float-to-string issue is a VERY frequently asked question.
>
> Why not check the FAQ?
>
> Its at http://www.cyberport.com/~tangent/palm/faq/. It points to an
article
> on the subject at
> http://www.cyberport.com/~tangent/palm/faq/articles/float.html. That
> article has code for a function called printDouble() which does what you
> want.
>
> --
> Ben Combee
> Veriprise Wireless <http://www.veriprise.com>
>
>
The whole float-to-string issue is a VERY frequently asked question.
but on the other hand, i can't convert the ending float result to a string.
the function below compiles fine, but causes a bus error on the emulator
when running:
CharPtr DblToStr( double pFloat )
{
FlpCompDouble flpObj;
CharPtr sFloat;
sFloat = "0";
// Convert a float to a string
flpObj.d = pFloat;
FlpFToA( flpObj.fd, sFloat );
return ( sFloat );
}
i think i saw a post on this same question before, but i don't think it was
answered. any ideas?
thanks,
-dan-
--
"Jay Hong" <jh...@lancercorp.com> wrote in message
news:Ib1VYZw...@www.massena.com...
I have to warn you that I am just getting into this chaotic float/ascii
mess, so I haven't tried this out yet. I still have brain-fry from not
realizing that Flp* and Fpl* are different (those sneaky Palm library
programmers:/). Just wanted to tell you far back you need to go to find
something truly useful in this area.
Mark Hamann
Dan Miller <dmi...@dmxcoding.com> wrote in message
news:A2Dtyfs...@www.massena.com...
The code in printDouble was written for the 3.1 SDK, then ported to the 3.5
SDK. You would be best served by updating the the PalmOS 3.5 SDK,
especially if you're doing new development. Barring that, just remove those
two lines -- they aren't needed for SDK 3.1.
if possible, could you just send me the post ... or perhaps the code that
converts double-to-string? i'd really appreciate it.
thanks,
--
-Dan-
"Mark Hamann" <mha...@hampton-power.com> wrote in message
news:73oAjv0...@www.massena.com...
here's the function that i did ...... the enviroment is as follows:
Compiler: CodeWarrior ( i started out with lite, but when i upgraded to
SDK 3.5 i think it erased the 'lite' part )
SDK version: 3.5 with upgrade
Emulator: 3.0a8
/***************************************************************************
************
*
* FUNCTION: DblToStr
*
* DESCRIPTION: Sets the string to a double value
*
* PARAMETERS: CharPtr str, double flpNumber, Int numFractDigits, Boolean
showSign
* ( str is the pointer receiving the converted double, flpNumber is the
* passed in double, numFractDigits is how many fractional places are
* to be returned, showSign tells the function if you want the string
* to include the +/- sign to be displayed. )
*
* RETURNED: nothing
*
****************************************************************************
***********/
static void DblToStr( CharPtr str, double flpNumber, Int numFractDigits,
Boolean showSign)
{
Long longNumber;
double flpIP, zeros, round;
Int i, strLen, startPtr, fracPos;
CharPtr tempStr;
Boolean isNeg;
tempStr = str;
isNeg = false;
startPtr = 0;
fracPos = 0;
// Put your custom Alert form here
if (numFractDigits < 0 || numFractDigits > 9)
FrmAlert(FloatErrorAlert);
if ( flpNumber < 0 )
{
isNeg = true;
flpNumber *= -1;
}
zeros = 1.0;
for (i=0; i<numFractDigits; i++)
zeros *= 10;
round = 0.5/zeros;
flpNumber += round;
flpIP = (int) flpNumber;
flpNumber = flpNumber - flpIP;
if ( ( isNeg) && (showSign) )
{
tempStr[startPtr] = '-';
startPtr += 1;
}
else if ( (!isNeg) && (showSign) )
{
tempStr[startPtr] = '+';
startPtr += 1;
}
// Get integer part and copy to temp string
StrIToA( &tempStr[startPtr], (long) flpIP );
// Get the length of the string and append a '.' to the end if it
strLen = StrLen( tempStr );
tempStr[strLen] = '.';
// Pad the decimal places with zeros
strLen = StrLen( tempStr );
for (i=0; i < numFractDigits; i++)
tempStr[strLen+i] = '0';
// Get the fractional part and append it after the '.'
longNumber = flpNumber * zeros;
if ( longNumber != 0 ) // only print if it is not a zero value - the
padding takes care of this
{
for ( i = longNumber*10; i<zeros; i *= 10 )
fracPos += 1;
for (i=1; i <= fracPos; i++ )
tempStr[strLen+i] = '0';
StrIToA( &tempStr[strLen+fracPos], longNumber );
}
// Append a null to the end of the string
strLen = StrLen( tempStr );
tempStr[strLen] = '\0';
// Point the new string to the given pointer
StrCopy( str, tempStr );
}
i tried to comment here and there, but probably not enough. anyhow, i hope
this helps anyone who is looking for the double-to-string function. below i
will post the function that i used to convert string-to-double (i didn't
write this one, but it seems to work good):
/***********************************************************************
*
* FUNCTION: StrToDbl
*
* DESCRIPTION: Gets a string value and returns a double
*
* PARAMETERS: CharPtr
*
* RETURNED: double
*
***********************************************************************/
double StrToDbl( CharPtr pString )
{
FlpCompDouble dObj;
dObj.fd = FlpAToF( pString );
return ( dObj.d );
}
this one seems much more simple that the double-to-string function.