This is really ugly, if you clean it up, let me know... (standard
disclaimers apply)
extern void ConvertExpToReal(CharPtr In,CharPtr tempStr)
{
// works fine, converted to drop dec if not >0
CharPtr e;
CharPtr dp;
UInt doneDec,i,x;
Boolean Handled = false;
Int decimal;
// if the first char == 0
tempStr[0]='\0';
if (In[0]=='0') // if the first char is a 0, then see if the next one is.
{
tempStr[0]='0';
if ((In[1]=='.') && (In[2]!='0'))
{
tempStr[1]='.';
tempStr[2]=In[2];
tempStr[3]='\0';
}
else
{
tempStr[1]='\0';
}
}
else
{
e = StrChr(In,'e');
if (e!=NULL) // if no e, then not an exponent
{
// e[0]='\0';
e++;
decimal = StrAToI(e);
if (decimal<0)
{
if (decimal==-1)
{
tempStr[0]='0';
tempStr[1]='.';
tempStr[2]=In[0];
tempStr[3]=In[2];
tempStr[4]='\0';
}
else
{
StrCopy(tempStr,"0.0");
}
}
else
{
tempStr[0]=In[0];
doneDec=1;
for (i=2;i<=StrLen(In);i++)
{
if ((i-2)==decimal)
{
tempStr[i-doneDec]='.';
doneDec=0;
}
tempStr[i-doneDec]=In[i];
}
dp= StrChr(tempStr,'.');
if (dp!=NULL)
{
if (dp[1]!='0')
dp[2]='\0';
else dp[0] = '\0';
// if the next pos after the dec pt is ! a zero, then do noral
}
else
StrCopy(tempStr,In);
}
}
else
{
StrCopy(tempStr,In);
}
x = StrLen(tempStr);
if (tempStr[x-1]=='.') tempStr[x-1]='\0'; // drop trailing decimal if
nuthin after it.
}
}
----------------------------------------------------------------------------
---------------------
"Comfort slays the passion of life and walks, grinning, at its funeral"