Possible Duplicate:
Format double value in scientific notation
How can I get a number to be displayed so that it fits on the screen on my calculator? I'm programming my first Android app, the screen, where my result is displayed has 10 places. Now, i want my result to be somehow converted to a format, that fits on the screen.
For example 9999999999+1 wouldn't fit anymore so it should display 1E+10 or something like that, I don't really get this notation. Numbers like 123456789.34567 should be converted to 123456789 Numbers like 0.00000000123456789 to 1.23456E+9 (789 don't fit on the screen anymore, therefore they should be simple left)
is there anything like that? or do I have to write my own function, but it would take lots of time
You should be able to use the DecimalFormat
class to format the numbers as per your requirement. Take a look at the documentation here.