Question

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 ?

Était-ce utile?

La solution

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;

Autres conseils

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);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top