Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double value negative after multiplication -Java

Tags:

java

In my code i have following line.

double temp=(c12*fileSize);
  • Here c12 is double and fileSizeis double
  • c12 have a value 1700 and
  • fileSize have a value 1944038

but after multiplication i am getting -990102696.

Can any one help me on it? Is that some size limits went wrong?

like image 993
user750932 Avatar asked May 12 '11 16:05

user750932


1 Answers

(int)1700 * (int)1944038 is equal to your -990102696.

Are you sure c12 and fileSize aren't integers? If they are, the multiplication occurs with integer types, integer overflow and it is being promoted to double afterwards.

like image 72
Tomasz Nurkiewicz Avatar answered Oct 15 '22 11:10

Tomasz Nurkiewicz