Example usage for java.text DecimalFormat getDecimalFormatSymbols

List of usage examples for java.text DecimalFormat getDecimalFormatSymbols

Introduction

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

Prototype

public DecimalFormatSymbols getDecimalFormatSymbols() 

Source Link

Document

Returns a copy of the decimal format symbols, which is generally not changed by the programmer or user.

Usage

From source file:Main.java

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

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

}

From source file:Main.java

public static void main(String args[]) {
    double d = 123456.7890;
    DecimalFormat df = new DecimalFormat("#####0.00");
    DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();

    dfs.setDecimalSeparator('.');
    df.setDecimalFormatSymbols(dfs);//from  ww  w  .  j  a v  a 2 s.com
    System.out.println(df.format(d));
}

From source file:MainClass.java

public static void main(String[] argv) {
    NumberFormat nf = NumberFormat.getInstance();
    if (nf instanceof DecimalFormat) {
        DecimalFormat df = (DecimalFormat) nf;

        DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();

        dfs.setCurrencySymbol("AD$");

        df.setDecimalFormatSymbols(dfs);

        df.applyPattern("\u00a4#,###.##");
    }/* w ww. j  ava2  s . com*/

    System.out.println(nf.format(1234.56));

}

From source file:Main.java

public static void main(String[] argv) {
    DecimalFormat df = (DecimalFormat) NumberFormat.getInstance();
    DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();

    dfs.setZeroDigit('\u0660');
    df.setDecimalFormatSymbols(dfs);/* w w w  . j  av  a2 s. c o m*/

    System.out.println(df.format(1234567.89));
}

From source file:Main.java

private static void updateDecimalSeparator(DecimalFormat numberFormat) {
    DecimalFormatSymbols symbol = numberFormat.getDecimalFormatSymbols();
    if (symbol.getDecimalSeparator() != DECIMAL_SEPARATOR) {
        symbol.setDecimalSeparator(DECIMAL_SEPARATOR);
        numberFormat.setDecimalFormatSymbols(symbol);
    }/*from ww w.  j a  va  2 s.c  o m*/
}

From source file:Main.java

public static String roundWithTwoDecimals(double number) {
    try {//from   w w  w . j  ava  2  s. c  om
        // format based on default locale
        DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(Locale.US);
        DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
        df.setDecimalFormatSymbols(dfs);
        df.applyPattern("#####0.00");
        return df.format(number);
    } catch (IllegalArgumentException e) {
        return null;
    }
}

From source file:com.ocs.dynamo.utils.PasteUtils.java

/**
 * Translates the decimal separator in the input to the format that is appropriate for the
 * provided Locale Note - this only works for input that does not contain any grouping
 * separators!/*from   ww w . j  av a2  s.c  o  m*/
 * 
 * @param input
 * @param locale
 * @return
 */
public static String translateSeparators(String input, Locale locale) {
    if (input == null) {
        return null;
    }

    DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(locale);
    char decimalSeparator = format.getDecimalFormatSymbols().getDecimalSeparator();
    if (decimalSeparator == '.') {
        input = input.replace(',', '.');
    } else {
        input = input.replace('.', ',');
    }
    return input;
}

From source file:nc.noumea.mairie.appock.core.utility.AppockUtil.java

private static DecimalFormat construitFormatterCfp(String formatCfp) {
    DecimalFormat formatter = new DecimalFormat(formatCfp);
    DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols();
    symbols.setGroupingSeparator(' ');
    formatter.setDecimalFormatSymbols(symbols);
    return formatter;
}

From source file:Currently.java

/**
 * Ignores any internal date format, and tries to show a complete
 * date/timp stamp in extended ISO 8601 format. UTC time (Zulu time)
 * or a local timezone will be used.<p>
 *
 * <table border=1>//from   www. j  a  v a 2 s .co  m
 * <tr><th>zone</th><th>format</th><th>fraction</td><th>example</th></tr>
 * <tr><td>local</td><td>basic</td><td>integral</td><td>20020523T140427-0500</td></tr>
 * <tr><td>UTC</td><td>basic</td><td>integral</td><td>20020523190427Z</td></tr>
 * <tr><td>local</td><td>extd.</td><td>integral</td><td>2002-05-23T14:04:27-05:00</td></tr>
 * <tr><td>UTC</td><td>extd.</td><td>integral</td><td>2002-05-23T19:04:27Z</td></tr>
 * <tr><td>local</td><td>basic</td><td>millis</td><td>20020523T140427.166-0500</td></tr>
 * <tr><td>UTC</td><td>basic</td><td>millis</td><td>20020523190427.166Z</td></tr>
 * <tr><td>local</td><td>extd.</td><td>millis</td><td>2002-05-23T14:04:27.166-05:00</td></tr>
 * <tr><td>UTC</td><td>extd.</td><td>millis</td><td>2002-05-23T19:04:27.166Z</td></tr>
 * </table><p>
 *
 * @param zuluTime returns a UTC formatted stamp, if true. Otherwise
 * the time will be formatted according to the local zone. Local time
 * should be prefixed with the 'T'.
 * @param extendedFormat will use the extended ISO 8601 format which
 * separates the different timestamp items. If false, the basic
 * format will be used. In UTC and basic format, the 'T' separator
 * will be omitted.
 * @param withMillis will put the millisecond extension into the timestamp.
 * If false, the time will be without millisecond fraction. The separator
 * is taken from {@link java.text.DecimalFormatSymbols#getMinusSign()},
 * which usually is a period or a comma.
 * @param now is a time stamp as Date.
 * @return an ISO 8601 formatted date and time representation for
 * the given point in time.
 */
public static String iso8601(boolean zuluTime, boolean extendedFormat, boolean withMillis, Date now) {
    Calendar c = Calendar.getInstance(zuluTime ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault());
    c.setTime(now);

    // set up formattting options
    DecimalFormat nf2 = new DecimalFormat("##00");
    DecimalFormat nf3 = new DecimalFormat("###000");
    DecimalFormat nf4 = new DecimalFormat("####0000");
    DecimalFormatSymbols dfs = nf2.getDecimalFormatSymbols();

    // allocate result string buffer
    int size = extendedFormat ? (zuluTime ? 25 : 30) : (zuluTime ? 21 : 25);
    if (!withMillis) {
        size -= 4;
    }
    StringBuffer result = new StringBuffer(size);

    result.append(nf4.format(c.get(Calendar.YEAR)));
    if (extendedFormat) {
        result.append('-'); // position 5
    }
    result.append(nf2.format(c.get(Calendar.MONTH) + 1));
    if (extendedFormat) {
        result.append('-'); // position 8
    }
    result.append(nf2.format(c.get(Calendar.DAY_OF_MONTH)));
    // generating UTC in basic format may leave out the 'T' separator
    if (extendedFormat || !zuluTime) {
        result.append('T'); // position 11
    }
    result.append(nf2.format(c.get(Calendar.HOUR_OF_DAY)));
    if (extendedFormat) {
        result.append(':'); // position 14
    }
    result.append(nf2.format(c.get(Calendar.MINUTE)));
    if (extendedFormat) {
        result.append(':'); // position 17
    }
    result.append(nf2.format(c.get(Calendar.SECOND)));

    if (withMillis) {
        // Though there is no explicit spec which allows a complete
        // timestamp with milliseconds, it is implied through two
        // levels, sigh. 5.3.4.2 allows decimal fractions with
        // time-only stamps that have a timezone. The intro of 5.4.2
        // allows 5.3.1.3.
        result.append(dfs.getDecimalSeparator()); // position 20
        result.append(nf3.format(c.get(Calendar.MILLISECOND)));
    }

    if (zuluTime) {
        // this is easy
        result.append('Z');
    } else {
        // time zone calculations
        int zone_offset = c.get(Calendar.ZONE_OFFSET) / 1000;
        int save_offset = c.get(Calendar.DST_OFFSET) / 1000;
        int diff = (zone_offset + save_offset) / 60;
        result.append(diff < 0 ? dfs.getMinusSign() : '+'); // position 24

        if (diff < 0) {
            diff = Math.abs(diff);
        }
        result.append(nf2.format(diff / 60));
        if (extendedFormat) {
            result.append(':');
        }
        result.append(nf2.format(diff % 60));
    }

    return result.toString();
}

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);
    }//  w  w w.ja v  a  2s . com

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

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