且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Java中使用双精度类型进行除法时出错

更新时间:2023-12-04 07:57:58

364/365执行整数除法(截断小数点)。

364/365 performs integer division (truncates the decimal).

尝试双重答案= 364.0 / 365; 强制其执行浮点除法。

Try double answer = 364.0/365; to force it to perform floating point division.

类似于:

double days_in_year = 365;
double answer = 364/days_in_year;

也可以工作,因为其中一个操作数不是整数。

would work as well, since one of the operands isn't an integer.