-1

I have different float values like

  • 0.0000009
  • 8145.32
  • 123.00001
  • 1235.01000

I want them showing to a TextView or converting them to string without getting an exponential notation. when I use String.format("%.8f", num), It is getting random values after the real number ( num = 8145.32 -> 8145.32539487).

Help me, Thank you

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Afinas EM
  • 2,755
  • 1
  • 15
  • 28

1 Answers1

1

Try this use DecimalFormat

DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features designed to make it possible to parse and format numbers in any locale, including support for Western, Arabic, and Indic digits

SAMPLE CODE

 Double value = 123456434.678;
 DecimalFormat decimalFormat = new DecimalFormat("#0.00");
 Log.e("MY_VALUES", decimalFormat.format(value));

OUTPUT

com.example.nilesh.testapp E/MY_VALUES: 123456434.68
AskNilesh
  • 67,701
  • 16
  • 123
  • 163