This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Type casting problem
- To: gcc-help at gcc dot gnu dot org
- Subject: Type casting problem
- From: Kevin Shallow <sourjan at yahoo dot com>
- Date: Wed, 6 Jun 2001 14:05:27 -0700 (PDT)
Hello all. I am having a bit a problem with type
casting a double to a long. I am using gcc version
2.96 20000731 (Red Hat Linux 7.1 2.96-81), on an x86
type processer.
Here's the code:
#include <stdio.h>
int main(int argc, char *argv[])
{
double amount;
double cost;
long iamount;
cost = 0.06;
amount = cost * 100;
iamount = (long)(((double)cost) * 100);
printf("Amount %lf\n", amount);
printf("Integer Amount %ld\n", iamount);
return (0);
}
Here's the output:
Amount 6.000000
Integer Amount 5
There should be no difference between the 2 numbers,
but the type cast seems to be losing some presision
somewhere. Any help or tips would be greatly
appeciated.
Thanks,
_Kevin
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.com/