本文整理汇总了Java中java.text.DecimalFormatSymbols.getGroupingSeparator方法的典型用法代码示例。如果您正苦于以下问题:Java DecimalFormatSymbols.getGroupingSeparator方法的具体用法?Java DecimalFormatSymbols.getGroupingSeparator怎么用?Java DecimalFormatSymbols.getGroupingSeparator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.DecimalFormatSymbols
的用法示例。
在下文中一共展示了DecimalFormatSymbols.getGroupingSeparator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rebuildConstants
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
/**
* If the locale changes, but the app is still in memory, you may need to rebuild these constants
*/
public static void rebuildConstants() {
DECIMAL_FORMAT = new DecimalFormatSymbols();
// These will already be known by Java
DECIMAL_POINT = DECIMAL_FORMAT.getDecimalSeparator();
DECIMAL_SEPARATOR = DECIMAL_FORMAT.getGroupingSeparator();
// Use a space for Bin and Hex
BINARY_SEPARATOR = ' ';
HEXADECIMAL_SEPARATOR = ' ';
// We have to be careful with the Matrix Separator.
// It defaults to "," but that's a common decimal point.
if (DECIMAL_POINT == ',') MATRIX_SEPARATOR = ';';
else MATRIX_SEPARATOR = ',';
String number = "A-F0-9" +
Pattern.quote(String.valueOf(DECIMAL_POINT)) +
Pattern.quote(String.valueOf(DECIMAL_SEPARATOR)) +
Pattern.quote(String.valueOf(BINARY_SEPARATOR)) +
Pattern.quote(String.valueOf(HEXADECIMAL_SEPARATOR));
REGEX_NUMBER = "[" + number + "]";
REGEX_NOT_NUMBER = "[^" + number + "]";
}
示例2: validateOnlyDigits
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
/**
* Validates that the given value contains only digits, but not e.g. a
* character 'd'. Java would interpret the input 3d as double value 3.0.
* Anyway, this must not succeed.
*
* @param valueToCheck
* The value to be checked.
* @param component
* The current component.
* @return <code>true</code> if the value is valid.
*/
private static boolean validateOnlyDigits(String valueToCheck,
FacesContext facesContext) {
Locale locale = LocaleHandler.getLocaleFromString(BaseBean
.getUserFromSession(facesContext).getLocale());
DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
boolean decSepFound = false;
for (char c : valueToCheck.toCharArray()) {
if (!decSepFound && c == dfs.getDecimalSeparator()) {
decSepFound = true;
continue;
}
if (c == dfs.getGroupingSeparator()) {
continue;
}
if (!Character.isDigit(c)) {
return false;
}
}
return true;
}
示例3: setupLocaleSymbolsInputValidation
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
/**
* Setup user input validation allowed symbols according to current Locale and number type
*/
protected void setupLocaleSymbolsInputValidation() {
Locale locale = LocalizationContext.getCurrent().filter(l -> l.isLocalized()).flatMap(l -> l.getLocale())
.orElse(getLocale());
if (locale == null) {
// use default
locale = Locale.getDefault();
}
// check grouping
boolean useGrouping = true;
if (getInternalField().getConverter() instanceof StringToNumberConverter) {
NumberFormat nf = ((StringToNumberConverter<?>) getInternalField().getConverter()).getNumberFormat(locale);
if (nf != null) {
useGrouping = nf.isGroupingUsed();
}
}
DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
char[] symbols = null;
if (useGrouping) {
if (TypeUtils.isDecimalNumber(getType())) {
symbols = new char[] { dfs.getGroupingSeparator(), dfs.getDecimalSeparator() };
} else {
symbols = new char[] { dfs.getGroupingSeparator() };
}
} else {
if (TypeUtils.isDecimalNumber(getType())) {
symbols = new char[] { dfs.getDecimalSeparator() };
}
}
getInternalField().setAllowedSymbols(symbols);
}
示例4: 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();
}
}
}
示例5: setupLocaleSymbolsInputValidation
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
/**
* Setup user input validation allowed symbols according to current Locale and number type
*/
protected void setupLocaleSymbolsInputValidation() {
Locale locale = LocalizationContext.getCurrent().filter(l -> l.isLocalized()).flatMap(l -> l.getLocale())
.orElse(getLocale());
if (locale == null) {
// use default
locale = Locale.getDefault();
}
// check grouping
boolean useGrouping = true;
NumberFormat nf = getConverter().getNumberFormat(locale);
if (nf != null) {
useGrouping = nf.isGroupingUsed();
}
DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
char[] symbols = null;
if (useGrouping) {
if (TypeUtils.isDecimalNumber(getType())) {
symbols = new char[] { dfs.getGroupingSeparator(), dfs.getDecimalSeparator() };
} else {
symbols = new char[] { dfs.getGroupingSeparator() };
}
} else {
if (TypeUtils.isDecimalNumber(getType())) {
symbols = new char[] { dfs.getDecimalSeparator() };
}
}
getInternalField().setAllowedSymbols(symbols);
}