Java Code Examples for java.text.DecimalFormat.setGroupingUsed()

The following are Jave code examples for showing how to use setGroupingUsed() of the java.text.DecimalFormat class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: util4j   File: TestDecimalFormat.java   Source Code and License Vote up 6 votes
public static void test2(DecimalFormat df) {
	int number = 155566;
	//默认整数部分三个一组,
	System.out.println(number);//输出格式155,566
	//设置每四个一组
	df.setGroupingSize(4);
	System.out.println(df.format(number));//输出格式为15,5566
	DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance();
	//设置小数点分隔符
	dfs.setDecimalSeparator(';');
	//设置分组分隔符
	dfs.setGroupingSeparator('a');
	df.setDecimalFormatSymbols(dfs);
	System.out.println(df.format(number));//15a5566
	System.out.println(df.format(11.22));//11;22
	//取消分组
	df.setGroupingUsed(false);
	System.out.println(df.format(number));
}
 
Example 2
Project: meuboleto   File: InterpretadorCodigoBarras.java   Source Code and License Vote up 5 votes
public static String parseToCash( String value) {
    double temp = parseToDouble(value);
    String pattern = "###,###.00";
    DecimalFormatSymbols ds = new DecimalFormatSymbols();
    ds.setDecimalSeparator(',');
    ds.setGroupingSeparator('.');
    DecimalFormat df = new DecimalFormat(pattern,ds);
    df.setGroupingUsed(true);
    return df.format(temp);
}
 
Example 3
Project: cuttlefish   File: TikzExporter.java   Source Code and License Vote up 5 votes
public TikzExporter() {
	colors = new HashMap<Color, String>();
	DecimalFormatSymbols symbols = new DecimalFormatSymbols(
			Locale.getDefault());
	symbols.setDecimalSeparator('.');
	formatter = new DecimalFormat("###.#######", symbols);
	formatter.setGroupingUsed(false);
	setScalingFactors(defaultNodeSizeFactor, defaultEdgeSizeFactor,
			defaultCoordinateFactor);
}
 
Example 4
Project: gdl2   File: DvQuantity.java   Source Code and License Vote up 5 votes
@Override
public String toString() {
    DecimalFormat format = new DecimalFormat();
    format.setMinimumFractionDigits(precision);
    format.setMaximumFractionDigits(precision);
    DecimalFormatSymbols dfs = format.getDecimalFormatSymbols();
    dfs.setDecimalSeparator(DECIMAL_SEPARATOR);
    format.setDecimalFormatSymbols(dfs);
    format.setGroupingUsed(false);
    return format.format(magnitude) + ((unit == null || unit.isEmpty()) ? "" : "," + getUnit());
}
 
Example 5
Project: oscm   File: PriceConverter.java   Source Code and License Vote up 5 votes
/**
 * Returns the formatted value as a String, which is displayed for a given
 * price of type BigDecimal. The formatting used takes into account the
 * given locale, and optionally a grouping separator based on the locale.
 * 
 * @param price
 *            the price as a BigDecimal to be formatted.
 * @param useGrouping
 *            a flag indicating whether a grouping for the formatting will
 *            be used or not.
 * @param locale
 *            the locale to use for the formatting.
 * @return the displayed price formatted value as a String.
 */
public String getValueToDisplay(BigDecimal price, boolean useGrouping,
        Locale locale) {

    DecimalFormat nf = new DecimalFormat();
    nf.setDecimalFormatSymbols(new DecimalFormatSymbols(locale));
    nf.setGroupingUsed(useGrouping);
    nf.setMinimumFractionDigits(MINIMUM_FRACTION_DIGIT);
    if (useGrouping) {
        nf.applyPattern(PriceConverter.FORMAT_PATTERN_WITH_GROUPING);
    } else {
        nf.applyPattern(PriceConverter.FORMAT_PATTERN_WITHOUT_GROUPING);
    }

    String formattedPrice;
    if (price == null) {
        formattedPrice = nf.format(BigDecimal.ZERO);

    } else {
        if (price.scale() > MINIMUM_FRACTION_DIGIT) {
            nf.setMaximumFractionDigits(price.scale());
        }
        formattedPrice = nf.format(price);
    }
    return formattedPrice;

}
 
Example 6
Project: morpheus-core   File: Matrix.java   Source Code and License Vote up 5 votes
/** Print the matrix to the output stream.   Line the elements up in
  * columns with a Fortran-like 'Fw.d' style format.
@param output Output stream.
@param w      Column width.
@param d      Number of digits after the decimal.
*/

public void print (PrintWriter output, int w, int d) {
   DecimalFormat format = new DecimalFormat();
   format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
   format.setMinimumIntegerDigits(1);
   format.setMaximumFractionDigits(d);
   format.setMinimumFractionDigits(d);
   format.setGroupingUsed(false);
   print(output,format,w+2);
}
 
Example 7
Project: oscm   File: DurationParameterValidator.java   Source Code and License Vote up 5 votes
/**
 * Taken from org.oscm.ui.common.DurationValidation
 * 
 * @param valueToCheck
 * @return
 */
private Number getParsedDuration(String valueToCheck) {
    DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.getDefault());
    DecimalFormat df = new DecimalFormat(DURATION_FORMAT, dfs);
    df.setGroupingUsed(true);
    try {
        return df.parse(valueToCheck);
    } catch (ParseException e) {
        return null;
    }
}
 
Example 8
Project: MapAnalyst   File: Matrix.java   Source Code and License Vote up 5 votes
/** Print the matrix to the output stream.   Line the elements up in
  * columns with a Fortran-like 'Fw.d' style format.
@param output Output stream.
@param w      Column width.
@param d      Number of digits after the decimal.
*/

public void print (PrintWriter output, int w, int d) {
   DecimalFormat format = new DecimalFormat();
   format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
   format.setMinimumIntegerDigits(1);
   format.setMaximumFractionDigits(d);
   format.setMinimumFractionDigits(d);
   format.setGroupingUsed(false);
   print(output,format,w+2);
}
 
Example 9
Project: FuelUp   File: VolumeUtil.java   Source Code and License Vote up 5 votes
public static String getFuelVolume(double value) {
    DecimalFormat bddf = new DecimalFormat();
    bddf.setGroupingUsed(false);
    bddf.setMaximumFractionDigits(2);
    bddf.setMinimumFractionDigits(0);

    return bddf.format(value);
}
 
Example 10
Project: financisto1-holo   File: CurrencyCache.java   Source Code and License Vote up 5 votes
public static DecimalFormat createCurrencyFormat(Currency c) {
	DecimalFormatSymbols dfs = new DecimalFormatSymbols();
	dfs.setDecimalSeparator(charOrEmpty(c.decimalSeparator, dfs.getDecimalSeparator()));
	dfs.setGroupingSeparator(charOrEmpty(c.groupSeparator, dfs.getGroupingSeparator()));
	dfs.setMonetaryDecimalSeparator(dfs.getDecimalSeparator());
	dfs.setCurrencySymbol(c.symbol);

	DecimalFormat df = new DecimalFormat("#,##0.00", dfs);
	df.setGroupingUsed(dfs.getGroupingSeparator() > 0);
	df.setMinimumFractionDigits(c.decimals);
	df.setMaximumFractionDigits(c.decimals);
	df.setDecimalSeparatorAlwaysShown(false);
	return df;
}
 
Example 11
Project: datarouter   File: NumberFormatter.java   Source Code and License Vote up 5 votes
public static String format(Number number, String prefix, String suffix, int numFractionDigits, boolean grouping){
	DecimalFormat df = new DecimalFormat();
	df.setMaximumFractionDigits(numFractionDigits);
	df.setMinimumFractionDigits(numFractionDigits);
	df.setRoundingMode(RoundingMode.HALF_UP);
	df.setGroupingUsed(grouping);
	df.setPositivePrefix(prefix);
	df.setNegativePrefix(prefix + "-");
	df.setPositiveSuffix(suffix);
	df.setNegativeSuffix(suffix);
	return df.format(number);
}
 
Example 12
Project: jaer   File: Matrix.java   Source Code and License Vote up 5 votes
/** Print the matrix to the output stream.   Line the elements up in
  * columns with a Fortran-like 'Fw.d' style format.
@param output Output stream.
@param w      Column width.
@param d      Number of digits after the decimal.
*/

public void print (PrintWriter output, int w, int d) {
   DecimalFormat format = new DecimalFormat();
   format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
   format.setMinimumIntegerDigits(1);
   format.setMaximumFractionDigits(d);
   format.setMinimumFractionDigits(d);
   format.setGroupingUsed(false);
   print(output,format,w+2);
}
 
Example 13
Project: cuttlefish   File: TikzExporter.java   Source Code and License Vote up 5 votes
/**
 * General constructor for the class, pure object oriented approach.
 * It is necessary to create the object with the network before printing.
 * @param network
 */
public TikzExporter(BrowsableNetwork network){			
	this.network = network;
	colors = new HashMap<Color, String>();
	DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.getDefault());
	symbols.setDecimalSeparator('.');
	formatter = new DecimalFormat("###.#######", symbols);
	formatter.setGroupingUsed(false);
}
 
Example 14
Project: intellij-randomness   File: DecimalInsertAction.java   Source Code and License Vote up 5 votes
/**
 * Returns a nicely formatted representation of a double.
 *
 * @param decimal a {@code double}
 * @return a nicely formatted representation of a double
 */
private String convertToString(final double decimal) {
    final DecimalFormat format = new DecimalFormat();
    format.setGroupingUsed(decimalSettings.getGroupingSeparator() != '\0');

    final DecimalFormatSymbols symbols = format.getDecimalFormatSymbols();
    symbols.setGroupingSeparator(decimalSettings.getGroupingSeparator());
    symbols.setDecimalSeparator(decimalSettings.getDecimalSeparator());
    format.setMinimumFractionDigits(decimalSettings.getDecimalCount());
    format.setMaximumFractionDigits(decimalSettings.getDecimalCount());
    format.setDecimalFormatSymbols(symbols);

    return format.format(decimal);
}
 
Example 15
Project: MARF-for-Android   File: Matrix.java   Source Code and License Vote up 5 votes
/**
 * Print the matrix to the output stream.   Line the elements up in
 * columns with a Fortran-like 'Fw.d' style format.
 *
 * @param output Output stream.
 * @param w      Column width.
 * @param d      Number of digits after the decimal.
 */

public void print(PrintWriter output, int w, int d) {
    DecimalFormat format = new DecimalFormat();
    format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
    format.setMinimumIntegerDigits(1);
    format.setMaximumFractionDigits(d);
    format.setMinimumFractionDigits(d);
    format.setGroupingUsed(false);
    print(output, format, w + 2);
}
 
Example 16
Project: hanlpStudy   File: Matrix.java   Source Code and License Vote up 5 votes
/**
 * Print the matrix to the output stream.   Line the elements up in
 * columns with a Fortran-like 'Fw.d' style format.
 *
 * @param output Output stream.
 * @param w      Column width.
 * @param d      Number of digits after the decimal.
 */

public void print(PrintWriter output, int w, int d)
{
    DecimalFormat format = new DecimalFormat();
    format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
    format.setMinimumIntegerDigits(1);
    format.setMaximumFractionDigits(d);
    format.setMinimumFractionDigits(d);
    format.setGroupingUsed(false);
    print(output, format, w + 2);
}
 
Example 17
Project: FuelUp   File: EditExpenseActivity.java   Source Code and License Vote up 4 votes
private String getPrice(BigDecimal price) {
    DecimalFormat bddf = new DecimalFormat();
    bddf.setGroupingUsed(false);
    return bddf.format(price.doubleValue());
}
 
Example 18
Project: geomapapp   File: CylindricalMapBorder.java   Source Code and License Vote up 4 votes
public String formatNum2(double inValue){
DecimalFormat twoDec = new DecimalFormat("0.00");
twoDec.setGroupingUsed(false);
return twoDec.format(inValue);
}
 
Example 19
Project: geomapapp   File: CylindricalMapBorder.java   Source Code and License Vote up 4 votes
public String formatNum1(double inValue){
DecimalFormat oneDec = new DecimalFormat("0.0");
oneDec.setGroupingUsed(false);
return oneDec.format(inValue);
}
 
Example 20
Project: oscm   File: ValueRounder.java   Source Code and License Vote up 3 votes
/**
 * Rounds a value by using the specified scale with half up rounding and
 * without grouping. Even if the last part of the decimal value is 0 in
 * specified fraction digits, always all decimal places are filled with 0.
 * (e.g. value 1.2, 5 fraction digits, en locale => '1.20000' will be
 * returned)
 * 
 * @param value
 *            Value to be formatted.
 * @param locale
 *            Current user's locale for formatting.
 * @param fractionDigits
 *            Number of decimal places.
 * @return
 */
public static String roundValue(BigDecimal value, Locale locale,
        int fractionDigits) {
    DecimalFormat df = new DecimalFormat();
    df.setDecimalFormatSymbols(new DecimalFormatSymbols(locale));
    df.setGroupingUsed(false);
    df.setMaximumFractionDigits(fractionDigits);
    df.setMinimumFractionDigits(fractionDigits);
    df.setRoundingMode(RoundingMode.HALF_UP);
    return df.format(value);
}