Domanda

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 ?

È stato utile?

Soluzione

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;

Altri suggerimenti

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);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top