Question

Here is the text view:

<TextView
android:id="@+id/input"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:gravity="right"
android:textAlignment="viewEnd"
android:textColor="#ffffff"
android:textSize="50sp"/>

I'm using :

String inputStr = doubleToString(result);
input.setText(inputStr);

The TextView simply expands by more lines to fit large numbers (now string). I guess that's because I have used WRAP_CONTENT as height but I can't use FILL_PARENT.

If I use android:lines="1" then I simply can't see all the numbers. So how do I convert the double into scientific notation before displaying in the TextView?

Edit

I just discovered that it is being displayed in scientific notation but only for values greater than 10^12 But they're not just visible.

So i just it to display for values greater than 1E10.

Was it helpful?

Solution

convert double to scientific notation like that

public static String parseToCientificNotation(double result) {
    int cont = 0;
    java.text.DecimalFormat DECIMAL_FORMATER = new java.text.DecimalFormat("0.##");
    while (((int) result) != 0) {
        result/= 10;
        cont++;
    }
    return DECIMAL_FORMATER.format(result).replace(",", ".") + " x10^ -" + cont;

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top