# Double question

Ah Sam

Greenhorn

Posts: 3

bart zagers

Ranch Hand

Posts: 234

posted 8 years ago

- 0

I'm sorry, but not a guru

double d = 2 / 3

Both 2 and 3 are integers, therefore an integer division is done which gives zero as the integer result. This result is then converted to a zero double.

double d = 2 / 3d

Here 3 is a double, therefore the 2 is converted to a double and a double division is done, which gives 0.666 as result that is assigned to the double d

(therefore for example

int i = 2 / 3 would work fine, and

int i = 2 / 3d not)

double d = 2 / 3

Both 2 and 3 are integers, therefore an integer division is done which gives zero as the integer result. This result is then converted to a zero double.

double d = 2 / 3d

Here 3 is a double, therefore the 2 is converted to a double and a double division is done, which gives 0.666 as result that is assigned to the double d

(therefore for example

int i = 2 / 3 would work fine, and

int i = 2 / 3d not)

posted 8 years ago

- 0

"myahsam", please check your private messages. You can see them by clicking My Private Messages.

I agree. Here's the link: http://aspose.com/file-tools |