Example usage for java.text DecimalFormat setDecimalFormatSymbols

List of usage examples for java.text DecimalFormat setDecimalFormatSymbols

Introduction

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

Prototype

public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols) 

Source Link

Document

Sets the decimal format symbols, which is generally not changed by the programmer or user.

Usage

From source file:ArabicDigitsI18N.java

public ArabicDigitsI18N() {
    DecimalFormat df = (DecimalFormat) NumberFormat.getInstance();
    DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();

    dfs.setZeroDigit('\u0660');
    df.setDecimalFormatSymbols(dfs);

    JLabel label = new JLabel(df.format(1234567.89));

    label.setFont(new Font("Lucida Sans", Font.PLAIN, 22));
    add(label);//from   w ww .  ja  v a 2  s. com
}

From source file:Main.java

public Main() {
    DecimalFormat df = (DecimalFormat) NumberFormat.getInstance();
    DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();

    dfs.setZeroDigit('\u0660');
    df.setDecimalFormatSymbols(dfs);

    JLabel label = new JLabel(df.format(1234567.89));

    label.setFont(new Font("Lucida Sans", Font.PLAIN, 22));
    add(label);//w  w w .j a va 2s.com
}

From source file:oracle.cubist.datasetBuilder.CubistDatasetBuilder.java

protected double parseDoubleFromCsv(String s) {
    /*try {//  w  w w.  j  ava 2  s .  c  o  m
    double ret = Double.parseDouble(s);
    System.out.println("Safely parsed "+s+" into "+ret);
    return ret;
    } catch (NumberFormatException n) {     */
    log.trace("Double.parseDouble failed on " + s);
    DecimalFormatSymbols symbols = new DecimalFormatSymbols();
    symbols.setDecimalSeparator(',');
    DecimalFormat dcf = new DecimalFormat();
    dcf.setDecimalFormatSymbols(symbols);
    try {
        double ret = dcf.parse(s).doubleValue();
        log.trace("Parsed " + s + " into " + dcf.parse(s).doubleValue());
        return ret;
    } catch (ParseException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        throw new RuntimeException("ciao");
    }
    //}
}

From source file:MainClass.java

public MainClass() {
    NumberFormat nf = NumberFormat.getInstance();
    if (nf instanceof DecimalFormat) {
        DecimalFormat df = (DecimalFormat) nf;
        DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();

        // set the beginning of the range to Arabic digits
        dfs.setZeroDigit('\u0660');
        df.setDecimalFormatSymbols(dfs);
    }//from w w w  .ja  v  a  2  s. co m

    JLabel label = new JLabel(nf.format(1234567.89));

    label.setFont(new Font("Lucida Sans", Font.PLAIN, 22));
    add(label);
}

From source file:com.ocs.dynamo.ui.converter.CurrencyBigDecimalConverter.java

@Override
protected DecimalFormat constructFormat(Locale locale) {
    // ignore the locale that is passed as a parameter, and use the default
    // locale instead so
    // that the number formatting is always the same
    DecimalFormat nf = (DecimalFormat) DecimalFormat.getCurrencyInstance(locale);
    DecimalFormatSymbols s = nf.getDecimalFormatSymbols();
    s.setCurrencySymbol(currencySymbol);
    nf.setDecimalFormatSymbols(s);
    return nf;//ww  w.ja v a 2 s. c  o m
}

From source file:thymeleafsandbox.springjsp.web.conversion.NumberFormatter.java

public Number parse(final String text, final Locale locale) throws ParseException {
    final DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getNumberInstance();
    final DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US);
    symbols.setGroupingSeparator('*');
    numberFormat.setDecimalFormatSymbols(symbols);
    return numberFormat.parse(text);
}

From source file:thymeleafsandbox.springjsp.web.conversion.NumberFormatter.java

public String print(final Number object, final Locale locale) {
    final DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getNumberInstance();
    final DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US);
    symbols.setGroupingSeparator('*');
    numberFormat.setDecimalFormatSymbols(symbols);
    return numberFormat.format(object);
}

From source file:org.mitre.math.linear.RandomMatrixExample.java

/**
 * //from  w  w w.  ja v  a  2 s .c o  m
 * @param m
 * @param width      Column width.
 * @param digits     Number of digits after the decimal.
 * @return
 */
public String matrix2String(RealMatrix m, int width, int digits) {
    DecimalFormat format = new DecimalFormat();
    format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
    format.setMinimumIntegerDigits(1);
    format.setMaximumFractionDigits(digits);
    format.setMinimumFractionDigits(digits);
    format.setGroupingUsed(false);

    StringBuilder output = new StringBuilder();
    output.append('\n'); // start on new line.
    for (int i = 0; i < m.getRowDimension(); i++) {
        for (int j = 0; j < m.getColumnDimension(); j++) {
            String s = format.format(m.getEntry(i, j)); // format the number
            int padding = Math.max(1, width - s.length()); // At _least_ 1 space
            for (int k = 0; k < padding; k++) {
                output.append(' ');
            }
            output.append(s);
        }
        output.append('\n');
    }
    output.append('\n'); // end with blank line.
    return output.toString();
}

From source file:org.clueminer.chameleon.GraphPropertyStore.java

public void printFancy(int w, int d) {
    DecimalFormat format = new DecimalFormat();
    format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
    format.setMinimumIntegerDigits(1);/*from ww  w  . ja  v a 2 s  . c o  m*/
    format.setMaximumFractionDigits(d);
    format.setMinimumFractionDigits(d);
    format.setGroupingUsed(false);
    printFancy(new PrintWriter(System.out, true), format, w + 2);
}

From source file:com.prowidesoftware.swift.model.field.Field.java

/**
 * Format the given object as a money number without currency information in format
 * @param aValue//from w  w  w  .j  ava 2  s .  c  o m
 * @return the formatted amount as String
 */
protected static String formatNumber(final Object aValue) {
    //create formatter for financial amounts
    final DecimalFormat fmt = new DecimalFormat("#,###.00");

    final NumberFormat f = NumberFormat.getInstance(Locale.getDefault());
    if (f instanceof DecimalFormat) {
        ((DecimalFormat) f).setDecimalSeparatorAlwaysShown(true);
        fmt.setDecimalFormatSymbols(((DecimalFormat) f).getDecimalFormatSymbols());
    }
    final String formatted = fmt.format(aValue);
    return formatted;
}