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())?
This did the trick:
DecimalFormat decim = new DecimalFormat("#,###.##");
tv.setText(decim.format(someFloat));
You can try
NumberFormat.getInstance().format(my number)
to format to default locale
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With