當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。