you can use the numbers with "strings" ... so you can works with
floats,double,integers because in really are strings.....
Ej. the number 3.550000000000 is a double.
you can pass a the number a string "3.55" rouding two decimals .
After passing string to double to operations..+,*,..
I use to this two routines to doubles:
**************************************************************++
double strToDouble(char *str)
{ Int i,start,length,punctPos;
double result,sign,fractPart;
result=fractPart=0.0;
length=punctPos=StrLen(str);
start=0;
sign=1.0;
if (str[0]=='-'){
sign=-1.0;
start=1;
}
for (i=start;i<length ;i++){
if (str[i]!='.')
{ if
((str[i]=='0')||(str[i]=='1')||(str[i]=='2')||(str[i]=='3')||(str[i]=='4')||(str[i]=='5')||(str[i]=='6')||(str[i]=='7')||(str[i]=='8')||(str[i]=='9')
)
result=result * 10.0+(str[i] - 0x30);
else { return 0.0;
}
}
else { punctPos=i;
break;}
}
if (str[punctPos]=='.')
{for(i=length-1;i>punctPos;i--)
{if
((str[i]=='0')||(str[i]=='1')||(str[i]=='2')||(str[i]=='3')||(str[i]=='4')||(str[i]=='5')||(str[i]=='6')||(str[i]=='7')||(str[i]=='8')||(str[i]=='9')
)
fractPart = fractPart/10.0 + (str[i] - 0x30);
else {return 0.0;
}
}
result +=fractPart / 10.0;
}
return result*sign;
}
***********************************************+
void doubleToStr (char *str,double flpNumber,Int numFractDigits)
{
long longNumber;
double flpIP,zeros,round;
int i,strLen,remainder;
char sign=' ';
if (flpNumber<0.0)
{ flpNumber=-flpNumber;
sign='-'; }
zeros =1.0;
for (i=0;i<numFractDigits;i++)
zeros*=10;
round=0.5/zeros;
flpNumber +=round;
flpIP=(long) flpNumber;
flpNumber = flpNumber - flpIP;
str[0]=sign;
if (sign=='-')
StrIToA(&str[1],(long) flpIP);
else
StrIToA(&str[0],(long) flpIP);
strLen=StrLen(str);
str[strLen]='.';
str[numFractDigits + strLen + 1] ='\0';
longNumber = flpNumber * zeros;
for (i=numFractDigits + strLen;i>strLen; i--)
{remainder = longNumber %10;
str[i]=remainder + 0x30;
longNumber /=10;
}
}
*****************************************************
>From: Stringer <[EMAIL PROTECTED]>
>Reply-To: "Palm Developer Forum" <[EMAIL PROTECTED]>
>To: "Palm Developer Forum" <[EMAIL PROTECTED]>
>Subject: Re: FloatManager
>Date: Thu, 09 May 2002 08:41:23 -0400
>
> >Subject: Re: FloatManager
> >From: "Rafail Mladenov" <[EMAIL PROTECTED]>
> >Date: Wed, 8 May 2002 09:59:37 +0300
> >But I cant get your idea about integers.
> >> However, if you are working with monetary units you will be
> >>better off using integers. You will notice rounding errors
> >>that will keep your calculations
> >> from being accurate to the penny, schilling, euro, whatever.
> >
> >How can I represent (for example) 3.55 as Integer ?
>
>Currency has, by its nature, a fixed and predicable number of
>decimal places.
>
>You strip out the decimal place and hold the value in a Int32 variable
>as "355". You just have to keep track of which fields hold currency
>and then add and delete the decimal point when needed to present
>the information to users.
>
>Roger Stringer
>Marietta Systems, Inc.
>
>
>--
>For information on using the Palm Developer Forums, or to unsubscribe,
>please see http://www.palmos.com/dev/support/forums/
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/