本文整理汇总了Java中java.text.DecimalFormatSymbols.getDecimalSeparator方法的典型用法代码示例。如果您正苦于以下问题:Java DecimalFormatSymbols.getDecimalSeparator方法的具体用法?Java DecimalFormatSymbols.getDecimalSeparator怎么用?Java DecimalFormatSymbols.getDecimalSeparator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.DecimalFormatSymbols
的用法示例。
在下文中一共展示了DecimalFormatSymbols.getDecimalSeparator方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: LocalizeWriter
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
public LocalizeWriter(Writer out, Locale locale, boolean localizeDigits, boolean isUpperCase)
{
super(out);
this.locale = locale;
this.localizeDigits = localizeDigits;
this.isUpperCase = isUpperCase;
if (locale != null)
{
DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(locale);
this.zero = decimalFormatSymbols.getZeroDigit();
this.decimalSeparator = decimalFormatSymbols.getDecimalSeparator();
}
else
{
this.zero = '0';
this.decimalSeparator = '.';
}
}
示例4: 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);
}
示例5: validatePrecision
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
/**
* Validates that the number of decimal places is not exceeding the amount
* given in {@link DEC_PLACES_BOUND}.
*
* @param valueToCheck
* The value to be checked.
* @param component
* The current component.
* @return <code>true</code> if the value is valid.
*/
private static boolean validatePrecision(String valueToCheck,
FacesContext facesContext) {
Locale locale = LocaleHandler.getLocaleFromString(BaseBean
.getUserFromSession(facesContext).getLocale());
DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
char decimalSeparator = dfs.getDecimalSeparator();
int pos = valueToCheck.lastIndexOf(decimalSeparator);
if (pos != -1 && valueToCheck.length() - 1 > pos + DEC_PLACES_BOUND) {
return false;
} else {
return true;
}
}
示例6: doubleFromString
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
private static double doubleFromString(String sz, EditMode em) {
if (sz.length() == 0)
return 0.0;
try {
if (em == EditMode.HHMM) {
String[] rgsz = sz.split(":");
if (rgsz.length == 1)
return (double) Integer.parseInt(sz);
else if (rgsz.length == 2) {
if (rgsz[0].length() == 0)
rgsz[0] = "0";
switch (rgsz[1].length()) {
case 0:
rgsz[1] = "00";
break;
case 1:
rgsz[1] = String.format("%s0", rgsz[1]);
break;
case 2:
break;
default:
rgsz[1] = rgsz[1].substring(0, 2);
}
int h = Integer.parseInt(rgsz[0]);
int m = Integer.parseInt(rgsz[1]);
return h + (m / 60.0);
} else
return 0.0;
} else {
// TODO: remove this when Android bug 2626 is fixed. See http://code.google.com/p/android/issues/detail?id=2626&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars.
DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.getDefault());
char c = dfs.getDecimalSeparator();
return m_df.parse(sz.replace('.', c).replace(',', c)).doubleValue();
}
} catch (Exception e) {
return 0.0;
}
}
示例7: create
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
private static DecimalStyle create(Locale locale) {
DecimalFormatSymbols oldSymbols = DecimalFormatSymbols.getInstance(locale);
char zeroDigit = oldSymbols.getZeroDigit();
char positiveSign = '+';
char negativeSign = oldSymbols.getMinusSign();
char decimalSeparator = oldSymbols.getDecimalSeparator();
if (zeroDigit == '0' && negativeSign == '-' && decimalSeparator == '.') {
return STANDARD;
}
return new DecimalStyle(zeroDigit, positiveSign, negativeSign, decimalSeparator);
}
示例8: 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);
}
示例9: AlphaNumericStringComparator
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
public AlphaNumericStringComparator(Locale locale) {
DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
char localeDecimalSeparator = dfs.getDecimalSeparator();
// alphaNumChunkPatter initialized here to get correct decimal separator for locale.
alphaNumChunkPattern = Pattern.compile("(\\d+\\" + localeDecimalSeparator + "\\d+)|(\\d+)|(\\D+)");
}
示例10: getDecimalSymbol
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
public char getDecimalSymbol(Locale value) {
DecimalFormatSymbols decimalSystem = new DecimalFormatSymbols(value);
return decimalSystem.getDecimalSeparator();
}
示例11: replaceWithLocaleDecimalSeparator
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
/**
* Replaces the double decimal separator '.' with the one from the users
* locale.
*
* @param user
* the user to get the locale from
* @param numberString
* the string representing a double value
* @return the number string with the decimal separator of the users locale
*/
private String replaceWithLocaleDecimalSeparator(PlatformUser user,
String numberString) {
Locale locale = LocaleHandler.getLocaleFromString(user.getLocale());
DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
char dfsChar = dfs.getDecimalSeparator();
numberString = numberString.replace('.', dfsChar);
return numberString;
}