(int) no funciona?

I want to convert double value of 1.09478878083135368E7 to int. so I use

int formatted = (int)1.09478878083135368E7;

Then I send this value to another activity as a string by using

final string distance = String.valueOf(formatted);

I'm expecting to see "1" as a result but what I'm getting is 10947878. Any idea?

preguntado el 12 de febrero de 14 a las 07:02

1 Respuestas

1.09478878083135368E7 .. Notice the E7, that's (científica) notación E for 'move the period E points right'.

Así que en tu caso; 1.09478878083135368E7 se convierte en 10947887.8083135368, so converting to an int gives us 10947887 (you have 10947878 which might have been a typo?)

Respondido 12 Feb 14, 07:02

to add, if you want the integer value, user Math.round - elpoosh

why ? using Math.round also get 10947878 - PascuaKim

Math.Round might actually get you +1 in this case because of the .8; so the number on a Math.Round sería 10947888 (maybe not what you want in this case?) - txtechhelp

thanks a lot textechhelp and thepoosh . I finally use Math.round :) - PascuaKim

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.