Reputation: 321
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));
Upvotes: 0
Views: 675
Reputation: 54214
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));
Upvotes: 1
Reputation: 22637
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
Upvotes: 0