本文整理汇总了Java中java.text.DecimalFormatSymbols.setExponentSeparator方法的典型用法代码示例。如果您正苦于以下问题:Java DecimalFormatSymbols.setExponentSeparator方法的具体用法?Java DecimalFormatSymbols.setExponentSeparator怎么用?Java DecimalFormatSymbols.setExponentSeparator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.DecimalFormatSymbols
的用法示例。
在下文中一共展示了DecimalFormatSymbols.setExponentSeparator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTestObject
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
private File createTestObject(String objectName, String expString){
DecimalFormatSymbols dfs= new DecimalFormatSymbols();
dfs.setExponentSeparator(expString);
dfs.setCurrencySymbol("*SpecialCurrencySymbol*");
logln(" The special exponent separator is set : " + dfs.getExponentSeparator());
logln(" The special currency symbol is set : " + dfs.getCurrencySymbol());
// 6345659: create a test object in the test.class dir where test user has a write permission.
File file = new File(System.getProperty("test.class", "."), objectName);
try (FileOutputStream ostream = new FileOutputStream(file)) {
ObjectOutputStream p = new ObjectOutputStream(ostream);
p.writeObject(dfs);
//System.out.println(" The special currency symbol is set : " + dfs.getCurrencySymbol());
return file;
} catch (Exception e){
errln("Test Malfunction in DFSSerialization: Exception while creating an object");
/*
* logically should not throw this exception as errln throws exception
* if not thrown yet - but in case errln got changed
*/
throw new RuntimeException("Test Malfunction: re-throwing the exception", e);
}
}
示例2: getDecimalFormat
import java.text.DecimalFormatSymbols; //导入方法依赖的package包/类
/**
* Procedure creates new dot-separated DecimalFormat
*/
public static DecimalFormat getDecimalFormat(String format)
{
DecimalFormat df = new DecimalFormat(format);
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
dfs.setDecimalSeparator('.');
dfs.setExponentSeparator("e");
df.setDecimalFormatSymbols(dfs);
return df;
}
示例3: 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.");
}
}