0

I am working on a simple app, actually my first attempt in Android.

Expected result

  • I need the result to be shown in the English Language only, in case the mobile language is in Hindi for example.
  • I want the number to be shown without the letter (E) when the number is long.

Code

protected void operation(char ope){
 double num1 = Double.parseDouble(txtNum1.getText().toString());
 double num2 = Double.parseDouble(txtNum2.getText().toString());
 double resultMulti = 0;
 switch (ope) {
   case '*':
     resultMulti = num1 * num2;
     long a3=(long)resultMulti;
     if (resultMulti-a3 <= 0)
        txtMultiResult.setText(a3 + "");
     else
        txtMultiResult.setText(String.format("%.2f",resultMulti));// without E but will be converted to Mobile Language

     // txtMultiResult.setText(resultMulti+""); // with E
     // txtMultiResult.setText(String.valueOf(resultMulti));// With E
     //  txtMultiResult.setText(Double.toString(resultMulti));// with E

     imm.hideSoftInputFromWindow(btnMulti.getWindowToken(),0);
     break;
    }
}
Dour High Arch
  • 21,513
  • 29
  • 75
  • 90
john
  • 19
  • 3
  • Possible duplicate of [How to Avoid Scientific Notation in Double?](https://stackoverflow.com/questions/20813631/how-to-avoid-scientific-notation-in-double) – Colonder Sep 01 '17 at 23:28

1 Answers1

0

How about using Locale.ENGLISH inside String.format()? As in like the following:

txtMultiResult.setText(String.format(Locale.ENGLISH, "%.2f", resultMulti));
afagarap
  • 650
  • 2
  • 10
  • 22