List of usage examples for java.text DecimalFormat getMinimumFractionDigits
@Override public int getMinimumFractionDigits()
From source file:Main.java
public static void main(String[] argv) throws Exception { DecimalFormat format = new DecimalFormat(); System.out.println(format.getMinimumFractionDigits()); }
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 av a 2 s. c o m //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 ww w. j ava 2 s. co m //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); } }
From source file:org.apache.cordova.core.Globalization.java
private JSONObject getNumberPattern(JSONArray options) throws GlobalizationError { JSONObject obj = new JSONObject(); try {/*from w ww . j ava2 s . com*/ //uses java.text.DecimalFormat to format value DecimalFormat fmt = (DecimalFormat) DecimalFormat.getInstance(Locale.getDefault()); //default format String symbol = String.valueOf(fmt.getDecimalFormatSymbols().getDecimalSeparator()); //get Date value + options (if available) if (options.getJSONObject(0).length() > 0) { //options were included if (!((JSONObject) options.getJSONObject(0).get(OPTIONS)).isNull(TYPE)) { String fmtOpt = (String) ((JSONObject) options.getJSONObject(0).get(OPTIONS)).get(TYPE); if (fmtOpt.equalsIgnoreCase(CURRENCY)) { fmt = (DecimalFormat) DecimalFormat.getCurrencyInstance(Locale.getDefault()); symbol = fmt.getDecimalFormatSymbols().getCurrencySymbol(); } else if (fmtOpt.equalsIgnoreCase(PERCENT)) { fmt = (DecimalFormat) DecimalFormat.getPercentInstance(Locale.getDefault()); symbol = String.valueOf(fmt.getDecimalFormatSymbols().getPercent()); } } } //return properties obj.put("pattern", fmt.toPattern()); obj.put("symbol", symbol); obj.put("fraction", fmt.getMinimumFractionDigits()); obj.put("rounding", new Integer(0)); obj.put("positive", fmt.getPositivePrefix()); obj.put("negative", fmt.getNegativePrefix()); 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.PATTERN_ERROR); } }
From source file:org.apache.cordova.globalization.Globalization.java
private JSONObject getNumberPattern(JSONArray options) throws GlobalizationError { JSONObject obj = new JSONObject(); try {/*ww w . ja v a 2 s . c o m*/ //uses java.text.DecimalFormat to format value DecimalFormat fmt = (DecimalFormat) DecimalFormat.getInstance(Locale.getDefault()); //default format String symbol = String.valueOf(fmt.getDecimalFormatSymbols().getDecimalSeparator()); //get Date value + options (if available) if (options.getJSONObject(0).length() > 0) { //options were included if (!((JSONObject) options.getJSONObject(0).get(OPTIONS)).isNull(TYPE)) { String fmtOpt = (String) ((JSONObject) options.getJSONObject(0).get(OPTIONS)).get(TYPE); if (fmtOpt.equalsIgnoreCase(CURRENCY)) { fmt = (DecimalFormat) DecimalFormat.getCurrencyInstance(Locale.getDefault()); symbol = fmt.getDecimalFormatSymbols().getCurrencySymbol(); } else if (fmtOpt.equalsIgnoreCase(PERCENT)) { fmt = (DecimalFormat) DecimalFormat.getPercentInstance(Locale.getDefault()); symbol = String.valueOf(fmt.getDecimalFormatSymbols().getPercent()); } } } //return properties obj.put("pattern", fmt.toPattern()); obj.put("symbol", symbol); obj.put("fraction", fmt.getMinimumFractionDigits()); obj.put("rounding", Integer.valueOf(0)); obj.put("positive", fmt.getPositivePrefix()); obj.put("negative", fmt.getNegativePrefix()); 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.PATTERN_ERROR); } }