0

I have field on table as double (money data field), and i want to put it on Textview in format for example: money= 20.0 i want to show as: 20,0 or money = 190.25 i want to show as: 190,25

how to do that? this is my variable

txtTotalBill.setText(String.valueOf(total_bill));
Gabriel
  • 229
  • 4
  • 19

2 Answers2

2

You can use the String method replace to format your chain :

txtTotalBill.setText(String.valueOf(total_bill).replace('.', ','));
Jhiertz
  • 90
  • 6
1
String total = String.valueOf(total_bill);    

total = total.replace(".", ",");

try this and then settext hope it helps

txtTotalBill.setText(total.toString());

Or you can directly setText without variable like this:

txtTotalBill.setText(String.valueOf(total_bill).replace('.', ','));
Zaki Pathan
  • 1,762
  • 1
  • 13
  • 26
  • the solution works great, but i also need it become 2 digit after comma, this only replace the dot into comma, can we do that? – Gabriel Feb 24 '17 at 06:41
  • http://stackoverflow.com/a/10959430/7320259 check this. First covert string into double and do needfull with above link. Hope it helps @BayuWibawa – Zaki Pathan Feb 24 '17 at 06:53
  • the url you gave is not working if i only has 1 digit decimal like my example: 20.0, so i want to set 20,00 instead, can we do it? – Gabriel Feb 24 '17 at 07:51
  • nevermind, @ZakiPathan! i found it, must do String.format("%.2f", d) first then replace it – Gabriel Feb 24 '17 at 07:55