String to float Function

float StrToFloat(char *Source)
{
        char bp[12];
        char ap[12];
        char div[12];
        float apt,bpt;
        char ScrArr[12];
        int i,len,j;
        Boolean Point=false;
        
        if (StrChr(Source,'.')==NULL)
                return (float)StrAToI(Source);
        
        StrCopy(ScrArr,Source);
        len=StrLen(Source);
        j=0;
        div[j]='1';
        for(i=0;i<len;i++)
        {
                if(ScrArr[i]=='.')
                        Point=true;
                if(!Point)
                        bp[i]=ScrArr[i];
                else
                {
                        if (j==0)
                        {
                                bp[i]='\0';     
                                i++;
                        }       
                        ap[j]=ScrArr[i];
                        j++;
                        div[j]='0';
                }               
        }
        ap[j]='\0';
        div[j+1]='\0';
        bpt=(float)StrAToI(bp);
        apt=(float)StrAToI(ap);
        
        apt=apt/StrAToI(div);
        return bpt+apt;
}

[EMAIL PROTECTED]

priyesh

--- ajitnk <[EMAIL PROTECTED]> wrote:
> Hi ,
> 
> how do i convert a floating point number stored in a
> String(char*) to value
> of data type "float".
> 
> I need to perform some calculation on the floating
> point number stored in
> the String.
> 
> I found StrAToI function which coverts String to an
> Integer.but i am loosing
> the decial values.
> 
> any useful ideas in this regard would be
> appreciated.
> 
> thanx in advance
> Ajit
> 
> 
> -- 
> For information on using the Palm Developer Forums,
> or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to