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


Java DecimalFormat.setMultiplier方法代碼示例

本文整理匯總了Java中java.text.DecimalFormat.setMultiplier方法的典型用法代碼示例。如果您正苦於以下問題:Java DecimalFormat.setMultiplier方法的具體用法?Java DecimalFormat.setMultiplier怎麽用?Java DecimalFormat.setMultiplier使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.text.DecimalFormat的用法示例。


在下文中一共展示了DecimalFormat.setMultiplier方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.text.DecimalFormat; //導入方法依賴的package包/類
public static void main(String[] args) {
    DecimalFormat nf = (DecimalFormat) DecimalFormat
            .getPercentInstance(Locale.US);
    nf.setMaximumFractionDigits(3);
    nf.setMinimumFractionDigits(0);
    nf.setMultiplier(1);

    double d = 0.005678;
    String result = nf.format(d);
    if (!result.equals("0.006%")) {
        throw new RuntimeException("[Failed while formatting the double"
                + " value: " + d + " Expected: 0.006%, Found: " + result
                + "]");
    }

    d = 0.00;
    result = nf.format(d);
    if (!result.equals("0%")) {
        throw new RuntimeException("[Failed while formatting the double"
                + " value: " + d + " Expected: 0%, Found: " + result
                + "]");
    }

    d = 0.005678;
    result = nf.format(d);
    if (!result.equals("0.006%")) {
        throw new RuntimeException("[Failed while formatting the double"
                + " value: " + d + " Expected: 0.006%, Found: " + result
                + "]");
    }

    //checking with the non zero value
    d = 0.005678;
    result = nf.format(d);
    if (!result.equals("0.006%")) {
        throw new RuntimeException("[Failed while formatting the double"
                + " value: " + d + " Expected: 0.006%, Found: " + result
                + "]");
    }

    d = 9.00;
    result = nf.format(d);
    if (!result.equals("9%")) {
        throw new RuntimeException("[Failed while formatting the double"
                + " value: " + d + " Expected: 9%, Found: " + result
                + "]");
    }

    d = 0.005678;
    result = nf.format(d);
    if (!result.equals("0.006%")) {
        throw new RuntimeException("[Failed while formatting the double"
                + " value: " + d + " Expected: 0.006%, Found: " + result
                + "]");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:57,代碼來源:Bug8165466.java

示例2: createDecimalFormat

import java.text.DecimalFormat; //導入方法依賴的package包/類
/**
 * Returns a newly created DecimalFormat object
 * @param pattern       the format pattern
 * @param multiplier    the multiplier
 * @return              the formatter
 */
private static DecimalFormat createDecimalFormat(String pattern, int multiplier) {
    final DecimalFormat decimalFormat = new DecimalFormat(pattern);
    decimalFormat.setMultiplier(multiplier);
    return decimalFormat;
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:12,代碼來源:Parser.java


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