当前位置: 首页>>代码示例>>Java>>正文


Java DecimalFormat.setGroupingUsed方法代码示例

本文整理汇总了Java中java.text.DecimalFormat.setGroupingUsed方法的典型用法代码示例。如果您正苦于以下问题:Java DecimalFormat.setGroupingUsed方法的具体用法?Java DecimalFormat.setGroupingUsed怎么用?Java DecimalFormat.setGroupingUsed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.text.DecimalFormat的用法示例。


在下文中一共展示了DecimalFormat.setGroupingUsed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test2

import java.text.DecimalFormat; //导入方法依赖的package包/类
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));
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:20,代码来源:TestDecimalFormat.java

示例2: parseToCash

import java.text.DecimalFormat; //导入方法依赖的package包/类
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);
}
 
开发者ID:ViniciusSossela,项目名称:meuboleto,代码行数:11,代码来源:InterpretadorCodigoBarras.java

示例3: TikzExporter

import java.text.DecimalFormat; //导入方法依赖的package包/类
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);
}
 
开发者ID:dev-cuttlefish,项目名称:cuttlefish,代码行数:11,代码来源:TikzExporter.java

示例4: toString

import java.text.DecimalFormat; //导入方法依赖的package包/类
@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());
}
 
开发者ID:gdl-lang,项目名称:gdl2,代码行数:12,代码来源:DvQuantity.java

示例5: getValueToDisplay

import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
 * 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;

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:41,代码来源:PriceConverter.java

示例6: print

import java.text.DecimalFormat; //导入方法依赖的package包/类
/** 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);
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:17,代码来源:Matrix.java

示例7: getParsedDuration

import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
 * 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;
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:17,代码来源:DurationParameterValidator.java

示例8: getFuelVolume

import java.text.DecimalFormat; //导入方法依赖的package包/类
public static String getFuelVolume(double value) {
    DecimalFormat bddf = new DecimalFormat();
    bddf.setGroupingUsed(false);
    bddf.setMaximumFractionDigits(2);
    bddf.setMinimumFractionDigits(0);

    return bddf.format(value);
}
 
开发者ID:piskula,项目名称:FuelUp,代码行数:9,代码来源:VolumeUtil.java

示例9: createCurrencyFormat

import java.text.DecimalFormat; //导入方法依赖的package包/类
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;
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:15,代码来源:CurrencyCache.java

示例10: format

import java.text.DecimalFormat; //导入方法依赖的package包/类
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);
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:13,代码来源:NumberFormatter.java

示例11: TikzExporter

import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:dev-cuttlefish,项目名称:cuttlefish,代码行数:14,代码来源:TikzExporter.java

示例12: convertToString

import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:FWDekker,项目名称:intellij-randomness,代码行数:20,代码来源:DecimalInsertAction.java

示例13: print

import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:souhaib100,项目名称:MARF-for-Android,代码行数:19,代码来源:Matrix.java

示例14: print

import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:priester,项目名称:hanlpStudy,代码行数:20,代码来源:Matrix.java

示例15: getPrice

import java.text.DecimalFormat; //导入方法依赖的package包/类
private String getPrice(BigDecimal price) {
    DecimalFormat bddf = new DecimalFormat();
    bddf.setGroupingUsed(false);
    return bddf.format(price.doubleValue());
}
 
开发者ID:piskula,项目名称:FuelUp,代码行数:6,代码来源:EditExpenseActivity.java


注:本文中的java.text.DecimalFormat.setGroupingUsed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。