开发者

Very small fractions and 'double' type

I'm using a formula of 1/x, where x could be very big (bigger than 1开发者_开发问答000)

When I use 'double' type, I always get zero!

For example:

        int numOfDays = 1000;

        double result = 1 / numOfDays;

Which type can I use?

Thanks in advance!!


You are doing integer division and assigning the result to a double.

Change one of the operands to a double or float, and you will be OK.

int numOfDays = 1000;
double result = 1.0 / numOfDays;

Or:

int numOfDays = 1000;
double result = 1D / numOfDays;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜