Example usage for java.text DecimalFormat getNegativePrefix

List of usage examples for java.text DecimalFormat getNegativePrefix

Introduction

In this page you can find the example usage for java.text DecimalFormat getNegativePrefix.

Prototype

public String getNegativePrefix() 

Source Link

Document

Get the negative prefix.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DecimalFormat format = new DecimalFormat();

    System.out.println(format.getNegativePrefix());

}

From source file:org.apache.cordova.core.Globalization.java

private JSONObject getNumberPattern(JSONArray options) throws GlobalizationError {
    JSONObject obj = new JSONObject();
    try {/*w w  w .  j a v  a 2  s  .  c om*/
        //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 {/*from   w w  w.jav  a 2  s  . co 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);
    }
}