0

I want to have my double displayed like this 12.34 but at the moment its displaying like this 12,34. I want to have a period instead of a comma. Can anyone help?

Double tmp = CalculatePercentage(model.getTotal(),model.getAchieved(),Double.parseDouble(model.getWeight()),"W");
holder.textView_contribution.setText("End Weight: "+String.format("%.2f", tmp));
Erbez
  • 321
  • 5
  • 17

2 Answers2

1

You can accomplish this by creating your own instance of DecimalFormat and configuring it (a) to use your custom decimal separator and (b) use your desired number of fractional digits:

DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
symbols.setDecimalSeparator('.');

DecimalFormat format = new DecimalFormat();
format.setDecimalFormatSymbols(symbols);
format.setMaximumFractionDigits(2);

You can then use this to set the value of your TextView

holder.textView_contribution.setText("End Weight: " + format.format(tmp));
Ben P.
  • 52,661
  • 6
  • 95
  • 123
0

It is most likely due to the locale of the device. The decimal separator can either be a period or a comma. https://en.wikipedia.org/wiki/Decimal_separator

EDIT: possibly relevant Force point (".") as decimal separator in java

Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134