本文整理匯總了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 );
}