0

I have a little problem in an app I am working on. I am using some double values and I want to place them in some TextViews, but when the number is placed, instead of "." it appears ",". I would like to have a dot so I can import the value with a substring.

DecimalFormat precision = new DecimalFormat("0.00");
final TextView totalPrice = (TextView) getView().findViewById(R.id.actualPrice);
double price = 200.12357123;
totalPrice.setText("$" + precision.format(price));

Inside the TextView will appear 200,12 and I would like to appear 200.12, so I can convert the text in a double value later on.

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134

3 Answers3

0

Try this

Locale currentLocale = Locale.getDefault();
String formatString = "#,###,###,###.##";
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(currentLocale);
otherSymbols.setDecimalSeparator(',');
otherSymbols.setGroupingSeparator('.');
DecimalFormat df = new DecimalFormat(formatString, otherSymbols);

double price = 200.12357123;

Log.i("TAG", "" + "$ " + df.format(price));

OUTPUT

enter image description here

Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31
0

Use below code it will give an exactly same answer as you want:

double price = 200.12357123;
String s=String.format(Locale.US, "$%.2f", price);
Patrick R
  • 6,621
  • 1
  • 24
  • 27
-2

You can change the '.' with ',' ,when you want to convert to double.

Levon Asatryan
  • 195
  • 1
  • 1
  • 9