How do I print a double value without scientific notation using Java?

前端 未结 14 856
一整个雨季
一整个雨季 2020-11-21 11:52

I want to print a double value in Java without exponential form.

double dexp = 12345678;
System.out.println(\"dexp: \"+dexp);

It shows this

14条回答
  •  一生所求
    2020-11-21 12:17

    Java/Kotlin compiler converts any value greater than 9999999 (greater than or equal to 10 million) to scientific notation ie. Epsilion notation.

    Ex: 12345678 is converted to 1.2345678E7

    Use this code to avoid automatic conversion to scientific notation:

    fun setTotalSalesValue(String total) {
            var valueWithoutEpsilon = total.toBigDecimal()
            /* Set the converted value to your android text view using setText() function */
            salesTextView.setText( valueWithoutEpsilon.toPlainString() )
        }
    

提交回复
热议问题