More Conversion Problems
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   dan_cabrera
Posted On:   Monday, May 14, 2001 06:47 PM

Why the following returns me a 0, insted of the correct value?

//Sampel1
int letsee1 = 2147483647;
int letsee2 = 2147483647;
double ty = letsee1 * letsee2;(64 bits)

System.out.println(ty); //This return 0, Why??

//Sampel2
int letsee1 = 2147483647;
int letsee2 = 2147483647;
double ty;

ty= letsee1 * letsee2;(64 bits)

System.out.println(ty); //This return 0, Why??

Re: More Conversion Problems

Posted By:   Michael_Wax  
Posted On:   Monday, May 14, 2001 07:38 PM

You are doing an implicit cast from int to double. As you note, the multiplication gives a 60+ bit number, which is much larger than a 32 bit int. On the cast of this (int) result to a double, you are getting a result of zero. You need to cast to double before the multiplication.
About | Sitemap | Contact