Pregunta

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 ?

¿Fue útil?

Solución

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;

Otros consejos

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);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top