I have an app that prints a calculated money value and I want to display that value with the default currency format.
For example in Europe you would write:
1.
to get device locale you could use this:
@TargetApi(Build.VERSION_CODES.N)
public static Locale getCurrentLocale(Context c) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return c.getResources().getConfiguration().getLocales().get(0);
} else {
//noinspection deprecation
return c.getResources().getConfiguration().locale;
}
and then to do format:
double num = 1323.526;
NumberFormat defaultFormat = NumberFormat.getCurrencyInstance(getCurrentLocale(getContext()));
defaultFormat.format(num)