本文整理汇总了Java中java.text.DecimalFormatSymbols.getExponentSeparator方法的典型用法代码示例。如果您正苦于以下问题:Java DecimalFormatSymbols.getExponentSeparator方法的具体用法?Java DecimalFormatSymbols.getExponentSeparator怎么用?Java DecimalFormatSymbols.getExponentSeparator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.DecimalFormatSymbols
的用法示例。
在下文中一共展示了DecimalFormatSymbols.getExponentSeparator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pattern
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
/** Return a representation of the pattern used by this instance for formatting and
* parsing. The format is similar to, but not the same as the format recognized by the
* {@link Builder#pattern} and {@link Builder#localizedPattern} methods. The pattern
* returned by this method is localized, any currency signs expressed are literally, and
* optional fractional decimal places are shown grouped in parentheses. */
public String pattern() { synchronized(numberFormat) {
StringBuilder groups = new StringBuilder();
for (int group : decimalGroups) {
groups.append("(").append(Strings.repeat("#", group)).append(")");
}
DecimalFormatSymbols s = numberFormat.getDecimalFormatSymbols();
String digit = String.valueOf(s.getDigit());
String exp = s.getExponentSeparator();
String groupSep = String.valueOf(s.getGroupingSeparator());
String moneySep = String.valueOf(s.getMonetaryDecimalSeparator());
String zero = String.valueOf(s.getZeroDigit());
String boundary = String.valueOf(s.getPatternSeparator());
String minus = String.valueOf(s.getMinusSign());
String decSep = String.valueOf(s.getDecimalSeparator());
String prefixAndNumber = "(^|" + boundary+ ")" +
"([^" + Matcher.quoteReplacement(digit + zero + groupSep + decSep + moneySep) + "']*('[^']*')?)*" +
"[" + Matcher.quoteReplacement(digit + zero + groupSep + decSep + moneySep + exp) + "]+";
return numberFormat.toLocalizedPattern().
replaceAll(prefixAndNumber, "$0" + groups.toString()).
replaceAll("¤¤", Matcher.quoteReplacement(coinCode())).
replaceAll("¤", Matcher.quoteReplacement(coinSymbol()));
}}
示例2: TestDFSSerialization
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
public void TestDFSSerialization(){
/*
* 1. read from the object created using jdk1.4.2
*/
File oldFile = new File(System.getProperty("test.src", "."), "DecimalFormatSymbols.142.txt");
DecimalFormatSymbols dfs142 = readTestObject(oldFile);
if (dfs142 != null){
if (dfs142.getExponentSeparator().equals("E") && dfs142.getCurrencySymbol().equals("*SpecialCurrencySymbol*")){
System.out.println("\n Deserialization of JDK1.4.2 Object from the current JDK: Passed.");
logln(" Deserialization of JDK1.4.2 Object from the current JDK: Passed.");
} else {
errln(" Deserialization of JDK1.4.2 Object from the current JDK was Failed:"
+dfs142.getCurrencySymbol()+" "+dfs142.getExponentSeparator());
/*
* logically should not throw this exception as errln throws exception
* if not thrown yet - but in case errln got changed
*/
throw new RuntimeException(" Deserialization of JDK1.4.2 Object from the current JDK was Failed:"
+dfs142.getCurrencySymbol()+" "+dfs142.getExponentSeparator());
}
}
/*
* 2. create a valid DecimalFormatSymbols object with current JDK, then read the object
*/
String validObject = "DecimalFormatSymbols.current";
File currentFile = createTestObject(validObject, "*SpecialExponentSeparator*");
DecimalFormatSymbols dfsValid = readTestObject(currentFile);
if (dfsValid != null){
if (dfsValid.getExponentSeparator().equals("*SpecialExponentSeparator*") &&
dfsValid.getCurrencySymbol().equals("*SpecialCurrencySymbol*")){
System.out.println(" Deserialization of current JDK Object from the current JDK: Passed.");
logln(" Deserialization of current JDK Object from the current JDK: Passed.");
} else {
errln(" Deserialization of current JDK Object from the current JDK was Failed:"
+dfsValid.getCurrencySymbol()+" "+dfsValid.getExponentSeparator());
/*
* logically should not throw this exception as errln throws exception
* if not thrown yet - but in case errln got changed
*/
throw new RuntimeException(" Deserialization of current Object from the current JDK was Failed:"
+dfsValid.getCurrencySymbol()+" "+dfsValid.getExponentSeparator());
}
}
/*
* 3. Try to create an valid DecimalFormatSymbols object by passing null
* to set null for the exponent separator symbol. Expect the NullPointerException.
*/
DecimalFormatSymbols symNPE = new DecimalFormatSymbols(Locale.US);
boolean npePassed = false;
try {
symNPE.setExponentSeparator(null);
} catch (NullPointerException npe){
npePassed = true;
System.out.println(" Trying to set exponent separator with null: Passed.");
logln(" Trying to set exponent separator with null: Passed.");
}
if (!npePassed){
System.out.println(" Trying to set exponent separator with null:Failed.");
errln(" Trying to set exponent separator with null:Failed.");
/*
* logically should not throw this exception as errln throws exception
* if not thrown yet - but in case errln got changed
*/
throw new RuntimeException(" Trying to set exponent separator with null:Failed.");
}
}