本文整理匯總了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);
}