本文整理汇总了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));
}
示例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);
}
示例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);
}
示例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());
}
示例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;
}
示例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);
}
示例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;
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例15: getPrice
import java.text.DecimalFormat; //导入方法依赖的package包/类
private String getPrice(BigDecimal price) {
DecimalFormat bddf = new DecimalFormat();
bddf.setGroupingUsed(false);
return bddf.format(price.doubleValue());
}