-1

i have a BufferedReader buf = new BufferedReader(new FileReader(file)); the result of buf i want to set in the EditText. I do it that way:

DecimalFormat REAL_FORMATTER = new DecimalFormat("0.##");

et202.setText(buf.readLine());
et203.setText(String.valueOf(REAL_FORMATTER.format(buf.readLine())));
et204.setText(buf.readLine());

It seems, that this isn't the right way, cause my app crashs.

But when I set the

et203.setText(String.valueOf(REAL_FORMATTER.format(buf.readLine())));

to

et203.setText(buf.readLine());

my app works fine. Is there a way to set a format from the BuefferedReader?

I just want that the EditText has this format: "0.00" -> show always 2 decimals like on the pic

Picture

noobee
  • 373
  • 1
  • 4
  • 10
  • Do you want decimal value set on `EditText` with two decimal points? Can you share what is there in your `file`? – Mohammad Tauqir Dec 27 '15 at 01:36
  • I already set the `EditText` to `android:inputType="numberDecimal"` The problem is, that in the `file` are only the numbers like `5` or `112` or `4472300` inside. But my app has to show `5.00` , `112.00` , `4472300.00` and so on. With the bufferedReader i can't do that. I don't know how to format the numbers from the file – noobee Dec 27 '15 at 01:55
  • When I use `et203.setText(buf.readLine());` the result is `5` and not `5.00` Therefore I tried `et203.setText(String.valueOf(REAL_FORMATTER.format(buf.readLine())));` but that make my app crash :( – noobee Dec 27 '15 at 02:31

1 Answers1

0

Try this

BufferedReader reader = new BufferedReader(new FileReader(file));       
String text = reader.readLine().toString();
et203.setText(String.format("%.2f", Double.parseDouble(text)));

Or

String text = reader.readLine().toString();
double d = Double.parseDouble(text);
DecimalFormat f = new DecimalFormat("##.00");
et203.setText(f.format(d)+"");
Mohammad Tauqir
  • 1,817
  • 1
  • 18
  • 53