EasterKim
EasterKim

Reputation: 125

(int) is not working?

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?

Upvotes: 1

Views: 183

Answers (1)

txtechhelp
txtechhelp

Reputation: 6777

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?)

Upvotes: 6

Related Questions