I found this code useful and interesting, but I don't understand how dSep is
defined. Is that a constant you defined somewhere or is that a Palm defined
type?
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Steve
Mann
Sent: Thursday, May 04, 2000 9:00 PM
To: Palm Developer Forum
Subject: Re: atof
<LYR3109-6663-2000.05.04-15.33.55--smann#[EMAIL PROTECTED]>
>My question is simple, I want to use a function like atof, where I pass in
a
>char * and getting back a float or double.
See the attached code.
>I don't know how to use the FloatMgr as they are require a FloatType
>structure that is not defined anywhere.
It actually is defined somewhere in the headers.
Regards,
Steve Mann
# # #
/************************************
* FUNCTION: StringToDouble
*
* DESCRIPTION: Extract a double-size floating point number from a
string.
* The string may have a leading negative sign
* and a decimal point. The result is
undefined if either the
* lefthand or righthand side of the string have more
* than ( MAX_DIGITS - 1 ) digits. In
this case, MAX_DIGITS
* should be 9 because StrAToI takes an
Int32.
*
* RETURNED: The converted result
************************************/
static double StringToDouble
(
Char * strP // ( in ) the string to convert
)
{
Char LHS [ MAX_DIGITS + 1 ]; // space for "-" sign
Char RHS [ MAX_DIGITS ];
double fval1 = 0.0;
double fval2 = 0.0;
double fresult;
UInt8 srcP = 0;
UInt8 dstP = 0;
// strip off LHS of number until string end or you hit a decimal or MAX out
while ( strP [ srcP ] != '\0' && strP [ srcP ] != dSep &&
dstP < MAX_DIGITS )
{
LHS [ dstP++ ] = strP [ srcP++ ];
}
LHS [ dstP++ ] = '\0';
// Skip the decimal point if there is one
if ( strP [ srcP ] == dSep )
{
srcP++;
}
// strip off RHS of number, stop at end of string or MAX out
dstP = 0;
while ( strP [ srcP ] != '\0' && dstP < MAX_DIGITS - 1 )
{
RHS [ dstP++ ] = strP [ srcP++ ];
}
RHS [ dstP ] = '\0';
// convert the two parts to integers
fval1 = ( double ) StrAToI ( LHS );
fval2 = ( double ) StrAToI ( RHS );
// convert RHS to proper fraction
for ( srcP = 0; srcP < StrLen ( RHS ); srcP++ )
{
fval2 = fval2 / 10.0;
}
// combine the results
fresult = fval1 + fval2;
return fresult;
}
--
-------------------------------------------
Creative Digital Publishing Inc.
1315 Palm Street, San Luis Obispo, CA 93401-3117
-------------------------------------------
805.784.9461 805.784.9462 (fax)
[EMAIL PROTECTED] http://www.cdpubs.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/