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


Java DecimalFormatSymbols.getExponentSeparator方法代碼示例

本文整理匯總了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()));
}}
 
開發者ID:creativechain,項目名稱:creacoinj,代碼行數:30,代碼來源:BtcFormat.java

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

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


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