本文整理汇总了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;
}