Tip: To quickly apply the Currency format, select the cell or range of cells that you want to format, and then press Ctrl+Shift+$. Like the Currency format, the Accounting format is used for monetary values.
When you apply the Currency format to a field, Access displays a currency symbol and two values after the decimal point, but it does not change the field's data type.
Decimal Points. In the US, dollars and cents are separated by a decimal point and thousands are separated by a comma. But in many countries the opposite is true—they use commas for fractional separators and decimals for thousand separators.
For sake of completeness suppose you want to display a price in phone's current locale (correct decimal mark and thousand separator) but with a currency of your choice.
NumberFormat format = NumberFormat.getCurrencyInstance(Locale.getDefault());
format.setCurrency(Currency.getInstance("CZK"));
String result = format.format(1234567.89);
result
would then hold these values:
CZK1,234,567.89
with US locale1 234 567,89 Kč
with Czech localeIf you'd like to omit the decimal part for prices (show $199
instead of $199.00
) call this before using the formatter:
format.setMinimumFractionDigits(0);
All options are listed in NumberFormat
docs.
I found the solution. THe class NumberFormat has a multitude of predefined formatters. There is also one for formatting currency Values.
If you use the static method getCurrencyInstance the class will return a formatter for the device default currency. I use the following code to set my result:
NumberFormat format = NumberFormat.getCurrencyInstance();
((TextView) findViewById(R.id.text_result)).setText(format.format(result));
Check out DecimalFormat
.
It has a variety of features designed to make it possible to parse and format numbers in any locale, including support for Western, Arabic, or Indic digits. It also supports different flavors of numbers, including integers ("123"), fixed-point numbers ("123.4"), scientific notation ("1.23E4"), percentages ("12%"), and currency amounts ("$123"). All of these flavors can be easily localized.
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)
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