See ChangeLog entry 2003-09-10 15:00 UTC-0400 David G. Holm <dholm@jsd-llc.com>
This commit is contained in:
@@ -156,3 +156,59 @@ int hb_stricmp( const char * s1, const char * s2 )
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* returns the numeric value of a character string representation of a number */
|
||||
double hb_strVal( const char * szText, ULONG ulLen )
|
||||
{
|
||||
long double ldValue = 0.0;
|
||||
ULONG ulPos;
|
||||
ULONG ulDecPos = 0;
|
||||
BOOL bNegative = FALSE;
|
||||
long double ldScale = 0.1L;
|
||||
|
||||
HB_TRACE(HB_TR_DEBUG, ("hb_strVal(%s, %d)", szText, ulLen));
|
||||
|
||||
/* Look for sign */
|
||||
|
||||
for( ulPos = 0; ulPos < ulLen; ulPos++ )
|
||||
{
|
||||
if( szText[ ulPos ] == '-' )
|
||||
{
|
||||
bNegative = TRUE;
|
||||
ulPos++;
|
||||
break;
|
||||
}
|
||||
else if( szText[ ulPos ] == '+' )
|
||||
{
|
||||
ulPos++;
|
||||
break;
|
||||
}
|
||||
else if( ! HB_ISSPACE( szText[ ulPos ] ) )
|
||||
break;
|
||||
}
|
||||
|
||||
/* Build the number */
|
||||
|
||||
for(; ulPos < ulLen; ulPos++ )
|
||||
{
|
||||
if( szText[ ulPos ] == '.' && ulDecPos == 0 )
|
||||
{
|
||||
ulDecPos++;
|
||||
ldScale = 0.1L;
|
||||
}
|
||||
else if( szText[ ulPos ] >= '0' && szText[ ulPos ] <= '9' )
|
||||
{
|
||||
if( ulDecPos )
|
||||
{
|
||||
ldValue += ldScale * ( long double )( szText[ ulPos ] - '0' );
|
||||
ldScale *= 0.1L;
|
||||
}
|
||||
else
|
||||
ldValue = ( ldValue * 10.0L ) + ( long double )( szText[ ulPos ] - '0' );
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return ( double )( bNegative && ldValue != 0.0L ? -ldValue : ldValue );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user