+3  A: 

That is the best solution, you should also check for "NumberFormatException" exceptions, just incase of non valid charecters. Then return feedback to the user if it's wrong.

If you don't want floats, your going to have to look at fixed point arthimetic. The reason they want you to avoid using float is because it's rarely implemented on phone cpu's(Probbly arm), and has to be implemented in software which is slow. Fixed point is usally surported in hardware.

UK-AL
Cool, google do specify that the float operations are likely to be software rather than hardware because of the mobile cpu, and thus slower.
brass-kazoo
+1  A: 

The reasons that using Double.parseDouble is the best solution:

  • On a normal CPU, float operations are implemented by hardware operations. This is most likely not built into a mobile CPU, and would be replaced by software operations (which are significantly slower).

  • Using static methods of Double, rather than creating an instance via new Double(txtInput) is better for memory usage as it means only the class definition is loaded into the JVM, and we never have additional overhead from state information created by an instance of Double.

  • An alternative to Double.parseDouble is Double.valueOf, but this returns an instance of Double, and then we have created an object unnecessarily since we are just unboxing it to a double primitive.

brass-kazoo