Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display number in Textview with thousand separator and decimal format

How can I format, according to Locale.getDefault() of device, a float greater than 999.

For decimal format currently I'm using this:

DecimalFormat decim = new DecimalFormat("#.##");
tv.setText(decim.format(someFloat));

And for thousand separator:

tv.setText(String.format(Locale.getDefault(), "%,d", someInt));

How can I combine both if I want to display 3.678,66 (or 3,678.66 - depending of Locale.getDefault())?

like image 725
Rodia Avatar asked Mar 04 '18 13:03

Rodia


2 Answers

This did the trick:

DecimalFormat decim = new DecimalFormat("#,###.##");
tv.setText(decim.format(someFloat));
like image 112
Rodia Avatar answered Nov 07 '22 12:11

Rodia


You can try

NumberFormat.getInstance().format(my number)

to format to default locale

like image 23
Thanasis Arvanitis Avatar answered Nov 07 '22 14:11

Thanasis Arvanitis