List of usage examples for java.text DecimalFormat setCurrency
@Override public void setCurrency(Currency currency)
From source file:Main.java
public static void main(String[] argv) throws Exception { DecimalFormat format = new DecimalFormat(); format.setCurrency(Currency.getInstance(Locale.GERMANY)); System.out.println(format.clone()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DecimalFormat format = new DecimalFormat(); format.setCurrency(Currency.getInstance(Locale.GERMANY)); System.out.println(format.getCurrency()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DecimalFormat format = new DecimalFormat(); format.setCurrency(Currency.getInstance(Locale.GERMANY)); DecimalFormat format1 = new DecimalFormat(); System.out.println(format1.equals(format)); }
From source file:Main.java
@NonNull static String convertAmount(int amount) { DecimalFormat formatter = (DecimalFormat) NumberFormat.getCurrencyInstance(); formatter.setCurrency(Currency.getInstance("EUR")); String symbol = formatter.getCurrency().getSymbol(); formatter.setNegativePrefix(symbol + "-"); formatter.setNegativeSuffix(""); return formatter.format((double) amount / 100.0); }
From source file:org.apache.cordova.core.Globalization.java
private JSONObject getCurrencyPattern(JSONArray options) throws GlobalizationError { JSONObject obj = new JSONObject(); try {// w w w. j a v a 2 s .c om //get ISO 4217 currency code String code = options.getJSONObject(0).getString(CURRENCYCODE); //uses java.text.DecimalFormat to format value DecimalFormat fmt = (DecimalFormat) DecimalFormat.getCurrencyInstance(Locale.getDefault()); //set currency format Currency currency = Currency.getInstance(code); fmt.setCurrency(currency); //return properties obj.put("pattern", fmt.toPattern()); obj.put("code", currency.getCurrencyCode()); obj.put("fraction", fmt.getMinimumFractionDigits()); obj.put("rounding", new Integer(0)); obj.put("decimal", String.valueOf(fmt.getDecimalFormatSymbols().getDecimalSeparator())); obj.put("grouping", String.valueOf(fmt.getDecimalFormatSymbols().getGroupingSeparator())); return obj; } catch (Exception ge) { throw new GlobalizationError(GlobalizationError.FORMATTING_ERROR); } }
From source file:org.apache.cordova.globalization.Globalization.java
private JSONObject getCurrencyPattern(JSONArray options) throws GlobalizationError { JSONObject obj = new JSONObject(); try {/*from w w w .ja v a 2s. c om*/ //get ISO 4217 currency code String code = options.getJSONObject(0).getString(CURRENCYCODE); //uses java.text.DecimalFormat to format value DecimalFormat fmt = (DecimalFormat) DecimalFormat.getCurrencyInstance(Locale.getDefault()); //set currency format Currency currency = Currency.getInstance(code); fmt.setCurrency(currency); //return properties obj.put("pattern", fmt.toPattern()); obj.put("code", currency.getCurrencyCode()); obj.put("fraction", fmt.getMinimumFractionDigits()); obj.put("rounding", Integer.valueOf(0)); obj.put("decimal", String.valueOf(fmt.getDecimalFormatSymbols().getDecimalSeparator())); obj.put("grouping", String.valueOf(fmt.getDecimalFormatSymbols().getGroupingSeparator())); return obj; } catch (Exception ge) { throw new GlobalizationError(GlobalizationError.FORMATTING_ERROR); } }