1

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?

1 Answer 1

6

1.09478878083135368E7 .. Notice the E7, that's (scientific) E notation for 'move the period E points right'.

So in your case; 1.09478878083135368E7 becomes 10947887.8083135368, so converting to an int gives us 10947887 (you have 10947878 which might have been a typo?)

4
  • 1
    to add, if you want the integer value, user Math.round
    – thepoosh
    Feb 12, 2014 at 7:45
  • why ? using Math.round also get 10947878
    – EasterKim
    Feb 12, 2014 at 7:57
  • 1
    Math.Round might actually get you +1 in this case because of the .8; so the number on a Math.Round would be 10947888 (maybe not what you want in this case?)
    – txtechhelp
    Feb 12, 2014 at 8:02
  • thanks a lot textechhelp and thepoosh . I finally use Math.round :)
    – EasterKim
    Feb 12, 2014 at 9:45

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.