本文整理汇总了Java中java.text.DecimalFormat.setMinimumIntegerDigits方法的典型用法代码示例。如果您正苦于以下问题:Java DecimalFormat.setMinimumIntegerDigits方法的具体用法?Java DecimalFormat.setMinimumIntegerDigits怎么用?Java DecimalFormat.setMinimumIntegerDigits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.DecimalFormat
的用法示例。
在下文中一共展示了DecimalFormat.setMinimumIntegerDigits方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: displayProbabilities
import java.text.DecimalFormat; //导入方法依赖的package包/类
private void displayProbabilities() {
final DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
symbols.setGroupingSeparator(',');
final DecimalFormat df = new DecimalFormat("", symbols);
df.setMaximumFractionDigits(1);
df.setRoundingMode(RoundingMode.HALF_UP);
df.setMinimumIntegerDigits(1);
Map<HiddenPower, Double> hiddenPowers = hiddenPowerCalculator.computeHiddenPower(pokemon);
double badHiddenPower = 0;
for (final HiddenPower hiddenPower: HiddenPower.values()) {
double probability = hiddenPowers.get(hiddenPower);
hiddenPowerLabels.get(hiddenPower.ordinal()).setText(hiddenPower.getName() + ": " + df.format(probability * 100) + "%");
if (hiddenPower.equals(HiddenPower.WATER) || hiddenPower.equals(HiddenPower.GRASS)) {
badHiddenPower+= probability;
}
}
feelsBadMan.setVisible(badHiddenPower >= 0.375);
}
示例2: format
import java.text.DecimalFormat; //导入方法依赖的package包/类
public String format(BigDecimal number) {
try {
// TODO : what amount of significant digits need to be supported here?
// - from the DecimalFormat docs:
// [significant digits] = [minimum integer digits] + [maximum fraction digits]
DecimalFormat jdkFormatter = new DecimalFormat( FORMAT_STRING );
jdkFormatter.setMinimumIntegerDigits( 1 );
jdkFormatter.setMaximumFractionDigits( Integer.MAX_VALUE );
return jdkFormatter.format( number );
}
catch (Throwable t) {
throw new HibernateException(
"Unable to format decimal literal in approximate format [" + number.toString() + "]",
t
);
}
}
示例3: test1
import java.text.DecimalFormat; //导入方法依赖的package包/类
public static void test1(DecimalFormat df) {
//默认显示3位小数
double d = 1.5555555;
System.out.println(df.format(d));//1.556
//设置小数点后最大位数为5
df.setMaximumFractionDigits(5);
df.setMinimumIntegerDigits(15);
System.out.println(df.format(d));//1.55556
df.setMaximumFractionDigits(2);
System.out.println(df.format(d));//1.56
//设置小数点后最小位数,不够的时候补0
df.setMinimumFractionDigits(10);
System.out.println(df.format(d));//1.5555555500
//设置整数部分最小长度为3,不够的时候补0
df.setMinimumIntegerDigits(3);
System.out.println(df.format(d));
//设置整数部分的最大值为2,当超过的时候会从个位数开始取相应的位数
df.setMaximumIntegerDigits(2);
System.out.println(df.format(d));
}
示例4: print
import java.text.DecimalFormat; //导入方法依赖的package包/类
/** Print the matrix to the output stream. Line the elements up in
* columns with a Fortran-like 'Fw.d' style format.
@param output Output stream.
@param w Column width.
@param d Number of digits after the decimal.
*/
public void print (PrintWriter output, int w, int d) {
DecimalFormat format = new DecimalFormat();
format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
format.setMinimumIntegerDigits(1);
format.setMaximumFractionDigits(d);
format.setMinimumFractionDigits(d);
format.setGroupingUsed(false);
print(output,format,w+2);
}
示例5: print
import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
* Print the matrix to the output stream. Line the elements up in
* columns with a Fortran-like 'Fw.d' style format.
*
* @param output Output stream.
* @param w Column width.
* @param d Number of digits after the decimal.
*/
public void print(PrintWriter output, int w, int d) {
DecimalFormat format = new DecimalFormat();
format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
format.setMinimumIntegerDigits(1);
format.setMaximumFractionDigits(d);
format.setMinimumFractionDigits(d);
format.setGroupingUsed(false);
print(output, format, w + 2);
}
示例6: print
import java.text.DecimalFormat; //导入方法依赖的package包/类
/**
* Print the matrix to the output stream. Line the elements up in
* columns with a Fortran-like 'Fw.d' style format.
*
* @param output Output stream.
* @param w Column width.
* @param d Number of digits after the decimal.
*/
public void print(PrintWriter output, int w, int d)
{
DecimalFormat format = new DecimalFormat();
format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
format.setMinimumIntegerDigits(1);
format.setMaximumFractionDigits(d);
format.setMinimumFractionDigits(d);
format.setGroupingUsed(false);
print(output, format, w + 2);
}
示例7: formatNumber
import java.text.DecimalFormat; //导入方法依赖的package包/类
public static String formatNumber(long value, long minDigits)
{
DecimalFormat fmt = new DecimalFormat("0", new DecimalFormatSymbols(java.util.Locale.US));
fmt.setMinimumIntegerDigits( (int) minDigits );
return fmt.format( value );
}