This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Type casting problem
- To: Ingo Krabbe <i dot krabbe at dokom dot net>
- Subject: Re: Type casting problem
- From: Der Herr Hofrat <der dot herr at hofr dot at>
- Date: Fri, 8 Jun 2001 07:08:00 +0200 (CEST)
- CC: Kevin Shallow <sourjan at yahoo dot com>, gcc-help at gcc dot gnu dot org
> >
> > 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
>
-O2 is the solution
note that this is not realy explicid typcasting related (that is implicid
casts do the same job) , so:
iamount = cost * 100;
will do the same
hofrat