當前位置: 首頁>>代碼示例>>Java>>正文


Java DecimalFormatSymbols.setExponentSeparator方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:DFSSerialization.java

示例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;
}
 
開發者ID:mkulesh,項目名稱:microMathematics,代碼行數:13,代碼來源:CompatUtils.java

示例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.");
    }

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:69,代碼來源:DFSSerialization.java


注:本文中的java.text.DecimalFormatSymbols.setExponentSeparator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。