I have double iD = 1.557760E12; I want to convert it to an int how can I do ? someone explaine to me please thanks a lot ?

有帮助吗?

解决方案

You cannot. This number, written out, is:

1557760000000

The max int is:

2147483648

This is clearly much smaller.

You can, however, cast to a long. Its max value is

9223372036854775808

which, even at a glance, is much larger than your double. Use the following code:

long iLong = (long)iD;

其他提示

round() will always round your double to the correct value, and then, it will be cast to an long which will truncate any decimal places. But after rounding, there will not be any fractional parts remaining.

long i =math.round(id);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top