Example usage for java.text DecimalFormat setGroupingSize

List of usage examples for java.text DecimalFormat setGroupingSize

Introduction

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

Prototype

public void setGroupingSize(int newValue) 

Source Link

Document

Set the grouping size.

Usage

From source file:com.eu.evaluation.server.eva.EvaluateExcutorTest.java

@Test
public void test() {
    double d = 0.987;
    logger.info("String.format = " + String.format("%.2f", d));
    DecimalFormat df = new DecimalFormat("*.00");
    logger.info("DecimalFormat = " + df.format(d));

    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(2);//from w w w.  j a  va2  s.c om
    logger.info("NumberFormat = " + nf.format(d));

    DecimalFormat formater = new DecimalFormat();
    formater.setMaximumFractionDigits(2);
    formater.setGroupingSize(0);
    formater.setRoundingMode(RoundingMode.FLOOR);
    logger.info("DecimalFormat = " + (formater.format(d)));
}

From source file:com.example.demo_highlights.slidingmenu.fragment.LeftFragment.java

String[] filesize(long size) {
    String str = "";
    if (size >= 1024) {
        str = "KB";
        size /= 1024;/*  w  ww  .  ja v  a 2 s .c o m*/
        if (size >= 1024) {
            str = "MB";
            size /= 1024;
        }
    }
    DecimalFormat formatter = new DecimalFormat();
    formatter.setGroupingSize(3);
    String result[] = new String[2];
    result[0] = formatter.format(size);
    result[1] = str;
    return result;
}

From source file:com.magestore.app.pos.service.config.POSConfigService.java

private DecimalFormat integetFormat(ConfigPriceFormat priceFormat) {
    // khi to interger format
    String pattern = "###,###";
    Locale locale = new Locale("vi", "VN");
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.getDefault());
    symbols.setGroupingSeparator(priceFormat.getGroupSymbol().charAt(0));
    DecimalFormat format = new DecimalFormat(pattern, symbols);
    format.setGroupingSize(priceFormat.getGroupLength());
    return format;
}

From source file:com.magestore.app.pos.service.config.POSConfigService.java

private DecimalFormat floatFormat(ConfigPriceFormat priceFormat) {
    // khi to float format
    String pattern = "###,###.#";
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.getDefault());
    symbols.setDecimalSeparator(priceFormat.getDecimalSymbol().charAt(0));
    symbols.setGroupingSeparator(priceFormat.getGroupSymbol().charAt(0));
    DecimalFormat format = new DecimalFormat(pattern, symbols);
    format.setGroupingSize(priceFormat.getGroupLength());
    format.setMaximumFractionDigits(priceFormat.getPrecision());
    format.setMinimumFractionDigits(priceFormat.getRequirePrecision());
    return format;
}

From source file:com.magestore.app.pos.service.config.POSConfigService.java

private DecimalFormat quantityFormat(ConfigQuantityFormat quantityFormat) {
    // khi to interger format
    // khi to float format
    String pattern = "###,###.#";
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.getDefault());
    symbols.setDecimalSeparator(quantityFormat.getDecimalSymbol().charAt(0));
    symbols.setGroupingSeparator(quantityFormat.getGroupSymbol().charAt(0));
    DecimalFormat format = new DecimalFormat(pattern, symbols);
    format.setGroupingSize(quantityFormat.getGroupLength());
    format.setMaximumFractionDigits(quantityFormat.getPrecision());
    format.setMinimumFractionDigits(0);//from   w  w w . j  a  v  a2 s.  co m
    return format;
}

From source file:com.magestore.app.pos.service.config.POSConfigService.java

private DecimalFormat currencyFormat(ConfigPriceFormat priceFormat) {
    // khi to currency format
    String pattern = "###,###.#";
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.getDefault());
    symbols.setDecimalSeparator('.');
    symbols.setGroupingSeparator('.');
    DecimalFormat currencyFormat = new DecimalFormat(pattern, symbols);
    currencyFormat.setGroupingSize(priceFormat.getGroupLength());
    currencyFormat.setMaximumFractionDigits(priceFormat.getPrecision());
    currencyFormat.setMinimumFractionDigits(priceFormat.getRequirePrecision());
    return currencyFormat;
}

From source file:com.magestore.app.pos.service.config.POSConfigService.java

private DecimalFormat currencyNosymbolFormat(ConfigPriceFormat priceFormat) {
    // khi to currency format
    String pattern = "###,###.#";
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.getDefault());
    symbols.setDecimalSeparator(priceFormat.getDecimalSymbol().charAt(0));
    symbols.setGroupingSeparator(priceFormat.getGroupSymbol().charAt(0));
    DecimalFormat currencyFormat = new DecimalFormat(pattern, symbols);
    currencyFormat.setGroupingSize(priceFormat.getGroupLength());
    currencyFormat.setMaximumFractionDigits(priceFormat.getPrecision());
    currencyFormat.setMinimumFractionDigits(priceFormat.getRequirePrecision());
    return currencyFormat;
}