本文整理匯總了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
+ "]");
}
}
示例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;
}