本文整理汇总了Java中java.text.DecimalFormatSymbols.setGroupingSeparator方法的典型用法代码示例。如果您正苦于以下问题:Java DecimalFormatSymbols.setGroupingSeparator方法的具体用法?Java DecimalFormatSymbols.setGroupingSeparator怎么用?Java DecimalFormatSymbols.setGroupingSeparator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.DecimalFormatSymbols
的用法示例。
在下文中一共展示了DecimalFormatSymbols.setGroupingSeparator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: displayProbabilities
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
private void displayProbabilities() {
final DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
symbols.setGroupingSeparator(',');
final DecimalFormat df = new DecimalFormat("", symbols);
df.setMaximumFractionDigits(1);
df.setRoundingMode(RoundingMode.HALF_UP);
df.setMinimumIntegerDigits(1);
Map<HiddenPower, Double> hiddenPowers = hiddenPowerCalculator.computeHiddenPower(pokemon);
double badHiddenPower = 0;
for (final HiddenPower hiddenPower: HiddenPower.values()) {
double probability = hiddenPowers.get(hiddenPower);
hiddenPowerLabels.get(hiddenPower.ordinal()).setText(hiddenPower.getName() + ": " + df.format(probability * 100) + "%");
if (hiddenPower.equals(HiddenPower.WATER) || hiddenPower.equals(HiddenPower.GRASS)) {
badHiddenPower+= probability;
}
}
feelsBadMan.setVisible(badHiddenPower >= 0.375);
}
示例2: _setUpDecimalSymbolFormatProperties
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
private void _setUpDecimalSymbolFormatProperties(
DecimalFormatSymbols symbols,
RequestContext reqCtx,
Locale locale
)
{
if (reqCtx != null)
{
char ch = (char) 0;
if ((ch = reqCtx.getDecimalSeparator()) != (char)0)
symbols.setDecimalSeparator(ch);
if ((ch = reqCtx.getNumberGroupingSeparator()) != (char)0)
symbols.setGroupingSeparator(ch);
}
else
{
if (_LOG.isWarning())
{
_LOG.warning("NULL_REQUESTCONTEXT", locale.toString());
}
}
}
示例3: test2
import java.text.DecimalFormatSymbols; //导入方法依赖的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));
}
示例4: main
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
public static void main(String[] args) {
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.getDefault());
otherSymbols.setDecimalSeparator(',');
otherSymbols.setGroupingSeparator('.');
DecimalFormat df = new DecimalFormat("###0.00", otherSymbols);
List<Double> prices = Arrays.stream(sc.nextLine().split(", "))
.map(Double::parseDouble).collect(Collectors.toList());
UnaryOperator<Double> uOp = (x) -> x * 1.2;
System.out.println("Prices with VAT:");
for(Double price : prices){
System.out.println(df.format(uOp.apply(price)));
}
}
示例5: printTestInfo
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
private void printTestInfo(int maxCacheSize) {
DecimalFormat grouped = new DecimalFormat("000,000");
DecimalFormatSymbols formatSymbols = grouped.getDecimalFormatSymbols();
formatSymbols.setGroupingSeparator(' ');
grouped.setDecimalFormatSymbols(formatSymbols);
System.out.format(
"Test will use %s bytes of memory of %s available%n"
+ "Available memory is %s with %d bytes pointer size - can save %s pointers%n"
+ "Max cache size: 2^%d = %s elements%n",
grouped.format(ShrinkAuxiliaryDataTest.getMemoryUsedByTest()),
grouped.format(Runtime.getRuntime().maxMemory()),
grouped.format(Runtime.getRuntime().maxMemory()
- ShrinkAuxiliaryDataTest.getMemoryUsedByTest()),
Unsafe.ADDRESS_SIZE,
grouped.format((Runtime.getRuntime().freeMemory()
- ShrinkAuxiliaryDataTest.getMemoryUsedByTest())
/ Unsafe.ADDRESS_SIZE),
maxCacheSize,
grouped.format((int) Math.pow(2, maxCacheSize))
);
}
示例6: toString
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
public String toString(Object obj){
DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.ROOT);
symbols.setDecimalSeparator('.');
symbols.setGroupingSeparator(',');
DecimalFormat formatDecimal = new DecimalFormat("#0.00", symbols);
formatDecimal.setRoundingMode(RoundingMode.HALF_UP);
return formatDecimal.format((Double) obj);
}
示例7: parseToCash
import java.text.DecimalFormatSymbols; //导入方法依赖的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);
}
示例8: StrictDecimalFormat
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
public StrictDecimalFormat(char decimalSeparator, char groupingSeparator) {
this();
DecimalFormatSymbols symbols = getDecimalFormatSymbols();
symbols.setDecimalSeparator(decimalSeparator);
symbols.setGroupingSeparator(groupingSeparator);
setDecimalFormatSymbols(symbols);
setGroupingUsed(true);
}
示例9: isDecimal
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
public static boolean isDecimal(String input) {
try {
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setGroupingSeparator(',');
symbols.setDecimalSeparator('.');
String pattern = "#,##0.0#";
DecimalFormat decimalFormat = new DecimalFormat(pattern, symbols);
BigDecimal bigDecimal = (BigDecimal) decimalFormat.parse(input);
return true;
} catch (Exception ex) {
return false;
}
}
示例10: initSettings
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
/***
* If user does not provide a valid locale it throws IllegalArgumentException.
*
* If throws an IllegalArgumentException the locale sets to default locale
*/
private void initSettings() {
boolean success = false;
while (!success) {
try {
fractionDigit = Currency.getInstance(locale).getDefaultFractionDigits();
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
if (mGroupDivider > 0)
symbols.setGroupingSeparator(mGroupDivider);
groupDivider = symbols.getGroupingSeparator();
if (mMonetaryDivider > 0)
symbols.setMonetaryDecimalSeparator(mMonetaryDivider);
monetaryDivider = symbols.getMonetaryDecimalSeparator();
currencySymbol = symbols.getCurrencySymbol();
DecimalFormat df = (DecimalFormat) DecimalFormat.getCurrencyInstance(locale);
numberFormat = new DecimalFormat(df.toPattern(), symbols);
success = true;
} catch (IllegalArgumentException e) {
Log.e(getClass().getCanonicalName(), e.getMessage());
locale = getDefaultLocale();
}
}
}
示例11: convertToString
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
/**
* Returns a nicely formatted representation of a long.
*
* @param integer a {@code long}
* @return a nicely formatted representation of a long
*/
private String convertToString(final long integer) {
final DecimalFormat format = new DecimalFormat();
format.setGroupingUsed(integerSettings.getGroupingSeparator() != '\0');
final DecimalFormatSymbols symbols = format.getDecimalFormatSymbols();
symbols.setGroupingSeparator(integerSettings.getGroupingSeparator());
format.setMinimumFractionDigits(0);
format.setMaximumFractionDigits(0);
format.setDecimalFormatSymbols(symbols);
return format.format(integer);
}
示例12: convertToString
import java.text.DecimalFormatSymbols; //导入方法依赖的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: StatsCommand
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
public StatsCommand(AvaIre avaire) {
super(avaire);
DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols();
decimalFormatSymbols.setDecimalSeparator('.');
decimalFormatSymbols.setGroupingSeparator(',');
number = new DecimalFormat("#,##0", decimalFormatSymbols);
decimalNumber = new DecimalFormat("#,##0.00", decimalFormatSymbols);
}
示例14: numberFormatter
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
/**
* @return a number formatter instance which prints numbers in a human
* readable form, like 9_223_372_036_854_775_807.
*/
public static NumberFormat numberFormatter() {
DecimalFormat df = new DecimalFormat();
DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
dfs.setGroupingSeparator('_');
dfs.setDecimalSeparator('.');
df.setDecimalFormatSymbols(dfs);
return df;
}
示例15: StringFormats
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
public StringFormats(){
formatWith4Decs = new DecimalFormat("0.0000");
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols();
otherSymbols.setDecimalSeparator('.');
otherSymbols.setGroupingSeparator(',');
formatWith4Decs.setDecimalFormatSymbols(otherSymbols);
formatWith2Decs = new DecimalFormat("0.00");
formatWith2Decs.setDecimalFormatSymbols(otherSymbols);
}