Example usage for java.text DecimalFormatSymbols setGroupingSeparator

List of usage examples for java.text DecimalFormatSymbols setGroupingSeparator

Introduction

In this page you can find the example usage for java.text DecimalFormatSymbols setGroupingSeparator.

Prototype

public void setGroupingSeparator(char groupingSeparator) 

Source Link

Document

Sets the character used for thousands separator.

Usage

From source file:DecimalFormatDemo.java

static public void main(String[] args) {

    customFormat("###,###.###", 123456.789);
    customFormat("###.##", 123456.789);
    customFormat("000000.000", 123.78);
    customFormat("$###,###.###", 12345.67);
    customFormat("\u00a5###,###.###", 12345.67);

    Locale currentLocale = new Locale("en", "US");

    DecimalFormatSymbols unusualSymbols = new DecimalFormatSymbols(currentLocale);
    unusualSymbols.setDecimalSeparator('|');
    unusualSymbols.setGroupingSeparator('^');
    String strange = "#,##0.###";
    DecimalFormat weirdFormatter = new DecimalFormat(strange, unusualSymbols);
    weirdFormatter.setGroupingSize(4);//  www  .ja v  a  2s.c  om
    String bizarre = weirdFormatter.format(12345.678);
    System.out.println(bizarre);

    Locale[] locales = { new Locale("en", "US"), new Locale("de", "DE"), new Locale("fr", "FR") };

    for (int i = 0; i < locales.length; i++) {
        localizedFormat("###,###.###", 123456.789, locales[i]);
    }

}

From source file:Main.java

public static String formatNumber(int number) {
    DecimalFormat formatter = new DecimalFormat();
    DecimalFormatSymbols symbol = new DecimalFormatSymbols();
    symbol.setGroupingSeparator('.');
    formatter.setDecimalFormatSymbols(symbol);
    return formatter.format(number);
}

From source file:Main.java

public static String formatBalance(BigDecimal balance, String curr, boolean round, DecimalFormat format) {
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    dfs.setDecimalSeparator(',');
    dfs.setGroupingSeparator(' ');
    DecimalFormat currency = format;
    if (currency == null) {
        if (!round) {
            currency = new DecimalFormat("#,##0.00 ");
        } else {/*from  w w  w  .j a  v  a  2s  .c o  m*/
            currency = new DecimalFormat("#,##0 ");
        }
    }
    currency.setDecimalFormatSymbols(dfs);
    return currency.format(balance.doubleValue()) + curr;
}

From source file:Main.java

public static String safeDoubleToCurrency(Double val) {
    BigDecimal value = BigDecimal.valueOf(val);
    DecimalFormat kursIndonesia = (DecimalFormat) DecimalFormat.getCurrencyInstance();
    DecimalFormatSymbols formatRp = new DecimalFormatSymbols();

    formatRp.setCurrencySymbol("");
    formatRp.setMonetaryDecimalSeparator('.');
    formatRp.setGroupingSeparator(',');

    kursIndonesia.setDecimalFormatSymbols(formatRp);
    kursIndonesia.setParseBigDecimal(true);
    if (val < 1)
        kursIndonesia.setMaximumFractionDigits(8);
    else if (val < 10)
        kursIndonesia.setMaximumFractionDigits(6);
    else if (val < 100)
        kursIndonesia.setMaximumFractionDigits(4);

    return kursIndonesia.format(value);
}

From source file:org.techytax.helper.AmountHelper.java

public static String formatWithEuroSymbol(BigInteger amount) {
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.GERMAN);
    otherSymbols.setDecimalSeparator(',');
    otherSymbols.setGroupingSeparator('.');
    DecimalFormat df = new DecimalFormat(" ###,###,###,##0", otherSymbols);
    return df.format(amount.doubleValue());
}

From source file:org.techytax.helper.AmountHelper.java

public static String formatWithEuroSymbol(BigDecimal amount) {
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.GERMAN);
    otherSymbols.setDecimalSeparator(',');
    otherSymbols.setGroupingSeparator('.');
    DecimalFormat df = new DecimalFormat(" ###,###,###,##0.00", otherSymbols);
    return df.format(amount.doubleValue());
}

From source file:org.techytax.helper.AmountHelper.java

public static String format(int amount) {
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.GERMAN);
    otherSymbols.setDecimalSeparator(',');
    otherSymbols.setGroupingSeparator('.');
    DecimalFormat df = new DecimalFormat("###,###,###,##0", otherSymbols);
    return df.format(amount);
}

From source file:org.techytax.helper.AmountHelper.java

public static String format(BigInteger amount) {
    if (amount == null) {
        return null;
    }//from w w w  .  ja va 2 s.  c  o  m
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.GERMAN);
    otherSymbols.setDecimalSeparator(',');
    otherSymbols.setGroupingSeparator('.');
    DecimalFormat df = new DecimalFormat("###,###,###,##0", otherSymbols);
    return df.format(amount);
}

From source file:org.techytax.helper.AmountHelper.java

public static BigInteger parse(String amount) throws ParseException {
    if (StringUtils.isEmpty(amount)) {
        return null;
    }/*from  ww  w .j  a v  a  2 s .c o m*/
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.GERMAN);
    otherSymbols.setDecimalSeparator(',');
    otherSymbols.setGroupingSeparator('.');
    DecimalFormat df = new DecimalFormat("###,###,###,##0", otherSymbols);
    return BigInteger.valueOf(df.parse(amount).intValue());
}

From source file:com.insightaction.util.DataLoader.java

private static BigDecimal getBigDecimal(String value) {
    DecimalFormatSymbols symbols = new DecimalFormatSymbols();
    symbols.setGroupingSeparator(',');
    symbols.setDecimalSeparator('.');
    String pattern = "#,##0.0#";
    DecimalFormat decimalFormat = new DecimalFormat(pattern, symbols);
    decimalFormat.setParseBigDecimal(true);

    BigDecimal bigDecimal = null;
    try {/*  w ww  .j  a v a 2 s  .co  m*/
        bigDecimal = (BigDecimal) decimalFormat.parse(value);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return bigDecimal;
}