📌  相关文章
📜  Java中的 DecimalFormat getMinimumIntegerDigits() 方法

📅  最后修改于: 2022-05-13 01:55:41.403000             🧑  作者: Mango

Java中的 DecimalFormat getMinimumIntegerDigits() 方法

getMinimumIntegerDigits()方法是Java中Java .text.DecimalFomrat类的内置方法,用于获取 Number 整数部分允许的最小位数。数字中的整数部分定义为小数点 (.) 之前的部分。例如,在数字 123, 45.678 中,整数部分是 123, 45。

语法

public int getMinimumIntegerDigits()

参数:该函数不接受任何参数。

返回值:该函数返回数字整数部分允许的最小位数。

下面是上述函数的实现:

程序 1

// Java program to illustrate the
// getMinimumIntegerDigits() method
  
import java.text.DecimalFormat;
import java.util.Currency;
import java.util.Locale;
  
public class Main {
    public static void main(String[] args)
    {
  
        // Create the DecimalFormat Instance
        DecimalFormat deciFormat = new DecimalFormat();
  
        // Print the minimum Integral digits allowed
        System.out.println(deciFormat.getMinimumIntegerDigits());
    }
}
输出:
1

方案二

// Java program to illustrate the
// getMinimumIntegerDigits() method
  
import java.text.DecimalFormat;
import java.util.Currency;
import java.util.Locale;
  
public class Main {
    public static void main(String[] args)
    {
  
        // Create the DecimalFormat Instance
        DecimalFormat deciFormat = new DecimalFormat();
        deciFormat.applyPattern("##.##");
  
        // Print the Minimum Integral digits allowed
        System.out.println(deciFormat.getMinimumIntegerDigits());
    }
}
输出:
1

参考:https: Java/text/DecimalFormat.html#getMinimumIntegerDigits()